Solved

sql case statement

Posted on 2011-03-07
3
252 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Encryption question 2 61
SQL Server Degrading on Write 13 70
Sql query 107 74
How do I subtract date and time within a same column in SQL 4 41
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…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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