CASE [expression]
WHEN [value | Boolean expression] THEN [return value]
ELSE [return value]
END
Example 1:
declare @Gender nvarchar(6)
set @Gender='M' select case when @Gender='M' then 'Male' else 'Female' End 'Gender'
#Results:
Gender
Male
Example 2:
declare @Gender nvarchar(6)
set @Gender='F' select case when @Gender='M' then 'Male' else 'Female' End 'Gender'
#Results:
Gender
Female
Example 3:
select Num, case Num
when 100 then 'A'
when 90 then 'B'
when 80 then 'C'
when 70 then 'D'
when 60 then 'E'
end 'Grade' from (
select (100)Num union
select (90) union
select (80) union
select (70) union
select (60)
)v1
#Results:
Num Grade
60 E
70 D
80 C
90 B
100 A