Link to home
Start Free TrialLog in
Avatar of sageryd
sagerydFlag for Sweden

asked on

CASE-statement syntax??

I want to make a CASE-statement in MS Access 2000, but I don't know the syntax for it! This how it's done in SQL Server:


SELECT 'Price Category' = CASE
     WHEN price IS NULL THEN 'Not yet priced'
     WHEN price < 10 THEN 'Very Reasonable Title'
     WHEN price >= 10 and price < 20 THEN 'Coffee Table Title'
     ELSE 'Expensive book!'
END
FROM titles
ORDER BY price



cheers

Johan
Avatar of RichardCorrie
RichardCorrie

Try this

SELECT iif(price IS NULL,"Not yet priced",iif(price < 10,"Very Reasonable Title",iif(price >= 10 and price < 20,
"Coffee Table Title","Expensive book!")))
as Price_Category
FROM titles
ORDER BY price

later,
Richard
Avatar of sageryd

ASKER

Thanx mate! Works just fine :)  But a case statement would be nicer... I'll leave the Q open for a bit longer, and see if anyone can show me the syntax of a case-statement, otherwise you're in for the points!


cheers
ASKER CERTIFIED SOLUTION
Avatar of cjswimmer
cjswimmer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
its a bit easier to work with than multiple IIfs.  The Switch just takes the first true expression and returns the second argument.  This makes it very easy to add and remove different evaluations, without having to worry about coordinating the True/False arguements with additinal IIF statements.
Avatar of sageryd

ASKER

Thanks! :)   Works just superb!


Richard, hope you understand that I'll give the points to cjswimmer. Thanks anyway for your help :)


cheers
I think its the closest thing you'll get to a case statement in Access.  I have no idea why its not supported in Access.