Solved

SQL Server - NEsted Case Statements

Posted on 2008-10-03
1
523 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
[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
1 Comment
 
LVL 143

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

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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