IF STATEMENT IN SQL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I trying to uses a function in MSACCESS APD which I have done in regular
queries many times, IF (field1=""txt""),field2,field3 AS NewField
I GET ERROR "Error in list of function arguments: '=' not recognized."
Can anyone help
 
Hi,

If you meant ADP, or Microsoft SQL Server, try CASE:


CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ELSE
defaultResult END


which is more "verbose" and "looking complex" than the procedural syntax of
SWITCH, in VBA:

SWITCH( condition1, result1, condition2, result2, true,
defaultResult)


but does exactly the same end result. If the conditions are always starting
with: variable =

as in

CASE WHEN x=1 THEN 'one' WHEN x=2 THEN 'two' WHEN x=3 THEN 'three'
ELSE 'not one-two-three' END

you can use the alternative syntax, a little bit simpler:

CASE x WHEN 1 THEN 'one' WHEN 2 THEN 'two' WHEN 3 THEN 'three' ELSE
'not one-two-three' END




Hoping it may help,
Vanderghast, Access MVP
 
Back
Top