--It is equivalent to if-else in C# to judge the content displayed by the custom column according to the value of the levle column
--requires that the data type behind then must be consistent
select * ,title=case
when [levle]=1 then 'rookie'
when [levle]=2 then 'veteran'
when [levle]=3 then 'master'
else 'hardcore'
end
from [user];
-- Equivalent to switch in C#
select * ,title=case [levle]
when 1 then 'rookie'
when 2 then 'old bird'
when 3 then 'master'
else 'hardcore'
end
from [user];
select * from tblscore;
select tScoreId,tSId,tEnglish,grade=case
when tEnglish>=95 then 'excellent'
when tEnglish>=80 then 'good'
when tEnglish>=70 then 'poor'
when tEnglish<60 then 'bad'
else 'bad' '
end
from dbo.TblScore