Solved

CASE-statement syntax??

Posted on 2001-06-14
6
4,736 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

706 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

17 Experts available now in Live!

Get 1:1 Help Now