.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Sample case and if else if ladder

Posted By:Maverick       Posted Date: March 16, 2011    Points: 40    Category: SQL Query    URL: http://www.dotnetspark.com  

Sample case and if else if ladder
 

DECLARE @TestVal INT

DECLARE @OUTPUT VARCHAR(200)
SET @TestVal = 1

SELECT @OUTPUT =
(
CASE  @TestVal
        WHEN 1 THEN 'First'
        WHEN 2 THEN 'Second'
        WHEN 3 THEN 'Third'
        ELSE 'Other'
END
)

PRINT @OUTPUT

SET @TestVal = 5

IF @TestVal = 1
SET @OUTPUT = '1'
ELSE IF @TestVal = 2
SET @OUTPUT = '2'
ELSE IF @TestVal = 3
SET @OUTPUT = '3'
ELSE
SET @OUTPUT = @TestVal

PRINT @OUTPUT


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend