Solved

SQL Server - NEsted Case Statements

Posted on 2008-10-03
1
510 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

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.
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…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

12 Experts available now in Live!

Get 1:1 Help Now