Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql case statement

Posted on 2011-03-07
3
Medium Priority
?
260 Views
Last Modified: 2012-06-27
sql case statement
multiple ifs  1 then

i dont want to do
if...
if..
if...
because there is only two thens total


0
Comment
Question by:rgb192
3 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 1400 total points
ID: 35059652
It takes the form


case
  when condition1 then
    Your statement
  when condition2 then
    Your statement
  when condition3 then
    Your statement
  else
    Your statement
end
0
 
LVL 8

Assisted Solution

by:raulggonzalez
raulggonzalez earned 600 total points
ID: 35059734
Or

case Input_expresion
     WHEN value THEN something
    WHEN value2 THEN something2
    ELSE something else
END As Colname

http://msdn.microsoft.com/en-us/library/ms181765.aspx

but you only can use it inside a query, if you want to use it like in other programming languages, I'm afraid you need to use

if
else if
else if
else



cheers
0
 

Author Closing Comment

by:rgb192
ID: 35097575
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

876 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