?
Solved

Is CASE Statement ANSI Standard or is specific to databases

Posted on 2010-08-22
3
Medium Priority
?
703 Views
Last Modified: 2012-08-13
Hi,

Is the implementation of CASE statement in SQL ANSI Standard or each database has a standard of its own when using case statement

For example if a table column say recipe_class returns when doing a select

Main course
Vegetable
Starch
Salad
Hors d'oeuvres
Dessert
Soup

then How do I do case in all kinds of databases that will do this

case 'Main Course' then 'M'
case 'Vegetable' then 'V'
else  'EX'


thanks
-anshu
0
Comment
Question by:anshuma
[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
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 1336 total points
ID: 33498312
case
when recipe_class = 'Main Course' then 'M'
when recipe_class = 'Vegetable' then 'V'
else  'EX'
end
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 1336 total points
ID: 33498360
ANSI-92 specifies the alternative form

CASE recipe_class
WHEN 'Main Course' then 'M'
when 'Vegetable' then 'V'
else  'EX'
end

But the first form has more support.  MySQL does not support this form, and from memory, Oracle doesn't either.
0
 
LVL 7

Assisted Solution

by:rashmi_vaghela
rashmi_vaghela earned 664 total points
ID: 33498424
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

765 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