Solved

SQL Server - NEsted Case Statements

Posted on 2008-10-03
1
516 Views
Last Modified: 2012-05-05
Is it possible to Write Nested CASE statments in SQL SERVER.
Can an example illustrating the syntax be given

Thanks
0
Comment
Question by:CWareIndia
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 22631805
>Is it possible to Write Nested CASE statments in SQL SERVER.
yes
SELECT CASE WHEN col1 = 'A' 
            THEN 123
            WHEN col1 = 'B'
            THEN CASE WHEN col2 IS NULL 
                      THEN 'N/A'
                      ELSE col2 
                  END
            ELSE '-N-'
        END expression
 

Open in new window

0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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.

825 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