拿case when then else end用法,列举个小例子:
例子一:
select b.ID,b.CorpName,(case b.Sex when '男' then '先生'
else '女士' end) as 'Sex' from CorpBasic b
例子二:
select name 姓名,case age when 20 then 青年 when 30 then 中年 when 60 then 老年 else 其它 end from age_tbl
例子三:
查询日志表是否存在修改记录
select vp.sid,vp.name ,vp.alikename ,vp.pid,vp.diffname
,case when exists (select 1 from ProductLog L where L.ProductID = vp.pid and L.EditDate>dateadd(month,-1,getdate()))
then 'true' else 'false' end as ifModify
from ViewProduct vp order by sid ,alikename ,diffname