Solved

CASE-statement syntax??

Posted on 2001-06-14
6
4,756 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
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
type of query 11 40
Steps to upgrade a Access 2003 application to 2013 3 33
Create a trap for no records found when user filters a form 11 28
Programmer 14 45
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now