DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Case And If Else Statement In Sql Server
// case and if else statement in sql server
DECLARE @MyVal INT
DECLARE @OUTPUTValues VARCHAR(200)
SET @MyVal = 1
SELECT @OUTPUTValues =
(
CASE @MyVal
WHEN 1 THEN 'test1'
WHEN 2 THEN 'test2'
WHEN 3 THEN 'test3'
ELSE 'New'
END
)
PRINT @OUTPUTValues
SET @TestVal = 5
IF @MyVal= 1
SET @OUTPUTValues= '1'
ELSE IF @MyVal= 2
SET @OUTPUTValues= '2'
ELSE IF @MyVal= 3
SET @OUTPUTValues= '3'
ELSE
SET @OUTPUTValues= @MyVal
PRINT @OUTPUTValues






Comments
Snippets Manager replied on Sat, 2012/05/05 - 11:58am