Solved

CASE-statement syntax??

Posted on 2001-06-14
6
4,779 Views
Last Modified: 2011-08-18
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
0
Comment
Question by:sageryd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:RichardCorrie
ID: 6190985
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
0
 
LVL 1

Author Comment

by:sageryd
ID: 6191042
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
0
 
LVL 6

Accepted Solution

by:
cjswimmer earned 50 total points
ID: 6191062
I would try the Switch function instead


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

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 6

Expert Comment

by:cjswimmer
ID: 6191093
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.
0
 
LVL 1

Author Comment

by:sageryd
ID: 6191109
Thanks! :)   Works just superb!


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


cheers
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6191111
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question