In this example first declare 1 variable for store value you can also use case when in SQL query
DECLARE @Type Int
-- Set value in declared variable
SET @Type = 1
-- now use case when like this normally it's just like if & else if condition
SELECT (CASE
WHEN @Type = 1 THEN 'Red' [if type = 1 { 'red' } ]
WHEN @Type = 2 THEN 'Green'
WHEN @Type = 3 THEN 'Blue'
ELSE 'No Colors' END)
DECLARE @Type Int
-- Set value in declared variable
SET @Type = 1
-- now use case when like this normally it's just like if & else if condition
SELECT (CASE
WHEN @Type = 1 THEN 'Red' [if type = 1 { 'red' } ]
WHEN @Type = 2 THEN 'Green'
WHEN @Type = 3 THEN 'Blue'
ELSE 'No Colors' END)
No comments :
Post a Comment