?
Solved

CASE-statement syntax??

Posted on 2001-06-14
6
Medium Priority
?
4,787 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 200 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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