Solved

Is CASE Statement ANSI Standard or is specific to databases

Posted on 2010-08-22
3
676 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
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 334 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 334 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 166 total points
ID: 33498424
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

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