If Statement in Query Expression (1 Viewer)

music_al

Registered User.
Local time
Today, 20:09
Joined
Nov 23, 2007
Messages
200
Hi

I need to construct this type of IF Statement in a query, but Im not sure how to...

If [THIS_FIELD] = "This_Value" Then "Return_This"

Ive tried a few syntax combinations but nothing seems to work. Can anyone help ?

Thanks


Allan
 

Scooterbug

Registered User.
Local time
Today, 15:09
Joined
Mar 27, 2009
Messages
853
You cant use an If...Then statement in a query. You have to use an IIF.

ie
Alias: iif([Expression]="YourValue",[DoIfTrue],[DoIfFalse])
 

mcclunyboy

Registered User.
Local time
Today, 12:09
Joined
Sep 8, 2009
Messages
292
Just a quick question for scooter - i understand IF's, well a bit but what is the difference between an IF and an IIF?
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 05:09
Joined
Jan 20, 2009
Messages
12,853
IIF a function where IF is a multiline procedure.
I believe it stands for Immediate IF.

Both have the same basic structure. If Then Else
Really IFF is little different from having made a simple IF procedure in a VBA standard module and named it as a function with three arguments.
 

DCrake

Remembered
Local time
Today, 20:09
Joined
Jun 8, 2005
Messages
8,632
One thing to consider when using immediate if's is that both the true and fale statement is tested to check where the logic/syntax is correct and working BEFORE the evaluation takes place, therefore they tend to take longer to process. This is especially relevant if you use nested iif's

Answer = Iff(Question1,True,Iff(Question2,True,False))

In the above example Access will first process Question1 then question2 then decide which one is correct and return the appropriate answer.

David
 

Users who are viewing this thread

Top Bottom