Sql server if-else以及switch


--相当于C#中的if-else 根据levle列的值来判断自定义列显示的内容
--要求then后面的数据类型必须一致

select * ,头衔=case
when [levle]=1 then '菜鸟'
when [levle]=2 then '老鸟'
when [levle]=3 then '大师'
else '骨灰级'
end
from [user];

--相当于C#中的switch

select * ,头衔=case [levle]
when 1 then '菜鸟'
when 2 then '老鸟'
when 3 then '大师'
else '骨灰级'
end
from [user];

select * from tblscore;

select tScoreId,tSId,tEnglish,等级=case
when tEnglish>=95 then '优'
when tEnglish>=80 then '良'
when tEnglish>=70 then '差'
when tEnglish<60 then '不良格'
else '不良格'
end
from dbo.TblScore


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM