Select
Case
When a is not null then a
When b is not null then b
When c is not null then c
When d is not null then d
Else ''
End 列名
From Table Name
SQL利用Case When Then多条件判断
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
(生成当天最大顺序编号)
select substring(convert(varchar(8), getdate(), 112), 1, 8)
+'568'
+ replicate('0', 4-len(max_ContractNo)) --以指定的次数重复字符表达式
+ cast(max_ContractNo as varchar(4))
from (select
case
when substring(max(My_ContractNo), 12, 4) is null then '1'