sageryd
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
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
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
cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
Thanks! :) Works just superb!
Richard, hope you understand that I'll give the points to cjswimmer. Thanks anyway for your help :)
cheers
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.
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