Re: IF THEN in query..Maybe IIf
- From: "tina" <nospam@xxxxxxxxxxx>
- Date: Sun, 13 Nov 2005 06:37:24 GMT
assuming that there is a primary key for the existing records in the data
table, which i'll call TableA, that matches a primary key in the imported
data, which i'll call TableB, you could try the following:
create a SELECT query on the two tables, INNER JOINed on the primary keys,
and
WHERE HOME_ADDRESS In ("Y", "YES")
that should pull all the matching records in the two tables, where the
TableB record is a home address.
now turn the query into an Update query. set each address field in TableA to
the address field in TableB. example:
UPDATE TableA INNER JOIN TableB ON TableA.PrimaryKey = TableB.PrimaryKey SET
TableA.StreetAddress = [TableB].[StreetAddress], TableA.City =
[TableB].[City], TableA.State = [TableB].[State], TableA.Zip =
[[TableB].[Zip]
WHERE HOME_ADDRESS In ("Y","Yes")
when testing an action query, it's always a good idea to back up the
database first - just in case...!
hth
"DieSpammersDie" <DieSpammersDie-no-spam@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message
news:YW50aWdvbmU=.4e3147c457e8d942c2e889a24c827957@xxxxxxxxxxxxxxxxxxxxxxxxxx
> I have a table that imports data from a file. However, I want to use an
> address depending on a condition in the data. Here is the scenario.
> Everyone in the table works at the same location, call it "1234 Main St,
> Sydney, MN 66789." However, if the data file has the person's home
address
> I want the query to update the table with the home address.
>
> Here is what I have done so far. Since everyone works in the same place,
I
> have hard coded the work address into the table:
>
> SELECT "1234 Main St." AS Address, "Sydney" AS City, "MN" AS State,
"66790"
> AS ZIP
>
> by doing this every single person in the table has the same default
address,
> which is the work address.
>
> Now here is the trick, if the data file has a home address then I want to
> replace the work address with the home address, if there is no home
address
> then I want to simply default to the work address (which is already the
> default).
>
> So, if the person lives at 999 Oak St., Sydney, MN 66793 I want to replace
> the default work address with the home address. The original data file
has
> a field, "HOME_ADDRESS' which is populated with either Y, YES, N, or NO.
So
> I will have to use the "LIKE" function, here is what I want to do in
pseudocode:
>
> If [HOME_ADDRESS] like 'Y*' then
> INSERT INTO TABLE
>
[(HOME_ADDRESS.Street),(HOME_ADDRESS.city),(HOME_ADDRESS.State),(HOME_ADDRES
S.Zip)]
>
>
> Since the table is already populated with the work address for every
> individual there is no need for an "ELSE" statement.
>
>
> I have been looking and found that the IIf statement may do what I want,
but
> I haven't been able to get the syntax correct, or I really don't
understand
> it. What would the proper access SQL statement be or could I do something
> in the design view?
>
>
.
- Follow-Ups:
- Re: IF THEN in query..Maybe IIf
- From: Vincent Johns
- Re: IF THEN in query..Maybe IIf
- Prev by Date: Re: Round function not working in query
- Next by Date: Re: Round function not working in query
- Previous by thread: Need help with a Batch Query
- Next by thread: Re: IF THEN in query..Maybe IIf
- Index(es):
Relevant Pages
|