Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF Function - Two Fields??

Status
Not open for further replies.

nike2000

Technical User
Apr 1, 2003
61
GB
Hi,
I have a query with a number of fields but would like to filter on the following two fields:

Location1 and Location2

The records in both of these fields will only have the following data:

London, New York, Tokyo, Hong Kong and can also be Null.

I would like to be able to show in the query only the records that have London in either of the two fields.
How can this be written in an IF Statement.

Thanks for your help
Nike
 
no need for a if just a -or- statment
where Location1='london' or Location2='london'
 
hi pwise,
Thanks for getting back to me.
This suggestion won't work because the Location 1 field can be London but the Location 2 field may have New York.
This could also be reversed.
These fields are independant of each other.
So this would mean that where London was on one field and not the other it would not show that record.
Nike
 
what results do you get when try this i think does work

SELECT Location.*
FROM Location
WHERE (((Location.Location1)="london")) OR (((Location.Location2)="london"));
 
Hi Pwise,
I already have the query built and is quite complex already.
It would be asier just to have the If statement, can this be done?
Many thanks
Nike
 
i dont know why it is so hard to add
(Location1="london" OR Location2="london")
to the end of the select statment

but if it is so hard try select ......., ([Location1]="london" OR [Location2]="london") as LocIsLondon

and in the where clause

where..... and ([Location1]="london" OR [Location2]="london")=true
 
because the same record can have two different locations placing London in both will only return records with London in both fields. There are variations in the two Location fields that can be London New York or New York London.

the Iif statement is the best option.
can this be done using an Iif statement?
 
You are incorrect in that statement. Placing "London" in both (for example) will include a record if EITHER location has the value "London" because the statement is an OR statement. Your assertion would be true if the boolean operator was an AND operator.

As to using IIF ... that's not it's function.

Clauses in the WHERE part of an SQL statement should return TRUE or FALSE. An IIF could be constructed like this:
Code:
   IIF (location1='London' OR location2='London',TRUE,FALSE)
but that is exactly equivalent to
Code:
   location1='London' OR location2='London'
without the IIF since the boolean expression returns TRUE or FALSE already.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top