Solved

SQL Server - NEsted Case Statements

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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