Solved

sql case statement

Posted on 2011-03-07
3
249 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:
ewangoya earned 350 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 150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adventure works database .msi 4 61
SQL Select - Finding chars in a column 2 57
Problem with SqlConnection 4 160
Table create permissions on SQL Server 2005 9 41
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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

11 Experts available now in Live!

Get 1:1 Help Now