Solved

Is CASE Statement ANSI Standard or is specific to databases

Posted on 2010-08-22
3
688 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Urgent help needed! Unable to to paste in query designer 29 55
Sql Server group by 10 51
Parse this column 6 35
Need help in debugging a UDF results 7 55
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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