Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql case statement

Posted on 2011-03-07
3
Medium Priority
?
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 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