create function level(@score real) --定义一个评级函数
returns char(8)
as
begin
declare @level char(8)
set @level=
case
when @score>100 then '输入错误'
when @score<=100 and @score>=90 then '优秀'
when @score<90 and @score>=80 then '良'
when @score<80 and @score>=70 then '中'
when @score<70 and @score>=60 then '及格'
else '不及格'
end
return @level
end
效果一样
case when 成绩>=90 then '优秀' when 成绩<60 then '不及格' else '及格' end
select dbo.level(成绩) from tb