All Visual Studio blogs in one place

AddThis Social Bookmark Button
As we know, we can write case expression in SQL in two ways.  As per BOL, defination of these two diffrent formats of CASE expression:
• The simple CASE expression compares an expression to a set of simple expressions to determine the result.
• The searched CASE expression evaluates a set of Boolean expressions to determine the result. Before today, I was thinking the both are same and one can be used in place of other directly.  But yesterday while answering one of the forum questions, I have noticed that handing of NULL can be the different between two CASE formats.
take an example DECLARE @T TABLE ( id INT NOT NULL , color INT) INSERT INTO @T (id,color) VALUES (1,1), (2,2), (3,3), (4,NULL)  Now in case statment --simpale case SELECT, CASE t.color WHEN 1 THEN 'Red' WHEN 2 THEN 'Blue' WHEN 3 THEN 'Green' ELSE 'NoColor' END AS Color FROM @t t --searched case SELECT, CASE WHEN t.color = 1 THEN 'Red' WHEN t.color = 2 THEN 'Blue' WHEN t.color =...(Read whole news on source site)



Enter your email address:

Delivered by FeedBurner

Increase your website traffic with


Anti-spam: How many eyes has a typical person?

Follow us on FB

Home : Blog List : Chintak's Blog : Simple VS Searched CASE expression