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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using IIF and OR

Status
Not open for further replies.

Jackcess

MIS
Dec 22, 2004
6
0
0
US
Hi, I am trying to do the following in a query.

If X equals A, B, or C, then return True, otherwise False.

I've tried using the following syntax but can't seem to get it right:

iif(x=A OR x=B OR x=C, "True","False)

Any advice? Thanks!

Jack
 
Status: IIf([X]="a",True,False) Or IIf([X]="b",True,False) Or IIf([X]="c",True,False)
 
You can also nest the IIF's
Code:
Status: IIf([X]="a",True,(If([X]="b",True,(IIf([X]="c",True,False)))))




Alan
Senility at its finest
 
And the simplest:
[tt]IIf(x='A' OR x='B' OR x='C', True, False)[/tt]
Or even simpler:
[tt](x='A' OR x='B' OR x='C')[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
A follow-up question: I'm trying to do the same query but need to use a wildcard, in other words my fields aren't just filled with A or B and C but with A01 or A19 or B01 or B02, etc. I thought the asterisk would work as a wildcard, i.e.:

IIf(x='A*' OR x='B*' OR x='C*', True, False)

... but the results are not identifying any records as meeting the condition.

What am I missing?

Rick
 
linsk33,

try using the LIKE instead of =

for example,

iif(name like 'A*', "Apple","Banana")

I used it once and it worked. i might have the syntax above a bit screwy though.
 
Another way:
IIf(x Like '[ABC]*', True, False)
Or:
(x Like '[ABC]*')

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top