Sqlserver case when 用法
题记:哈哈哈,今天写着写着竟然忘记了case when的用法,仅此来记录加深印象
select case when a.status=1 then '处理完成' when a.STATUS=99 then '已终止流程' else '处理中' end as status ,* from FLOW_EQUITYBILL a
我们类比一下更容易理解
case when 约等于 If
when 约等于 满足条件执行的代码
then 后面的when 相当于 else if
end 相当于 反括号)
当然 case when 也支持多条件 and 或者or
select top 100 State, JoinState, ( case when State = 1 and Joinstate = 0 then 2 when State = 1 and JoinState = 1 then 1 else 0 end ) as usestate from UserInfo

浙公网安备 33010602011771号