Wednesday, October 31, 2012

CASE Statement with Example in SQL SERVER

Posted by Rahul Kharde at 5:23 AM

The SQL CASE statement has WHEN, THEN, and ELSE clauses along with an END terminator.

Example

DECLARE @Gender VARCHAR(50)
SET @Gender='Male'

SELECT
CASE @Gender
          WHEN 'Male'   THEN 'M'
          WHEN 'Female' THEN 'F'
          ELSE  null
END       as 'Gender'

SQL Server compares this @Gender  to the expression  and when the values match, it returns the THEN clauses ‘M’or ‘F’. If none of the WHEN clauses match then it will return ‘null’ value


If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top