Use of CASE END in ms sql query to get conditional result column.

When we need some conditional output in sql script or query, below syntax will help to achieve.

SELECT Field1,Field2
(CASE
WHEN  exists(select top 1 Some_Field from Some_Table where [Condition])
THEN ‘OutputA’
ELSE ‘OutputB’
END) as ”AliasName”
From Table1

 

Read more,
https://siddharthboraniait.wordpress.com/2012/05/03/display-sql-server-messageusing-infomessage-event-from-sql-server-to-troubleshoot-stored-procedure

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s