【sql】条件判断(if,case when)
程序员文章站
2022-06-01 16:48:17
...
UPDATE [customer].[Customer]
SET InfoCompleteUserNo = #{infoCompleteUserNo},
InformationCompletionDate = GETDATE(),
InfoMaintainFlag = 0,
[DemandStateStatus]=IIF([DemandStateStatus]=0,5,[DemandStateStatus]),
[DemandStatusChangeDate]=IIF([DemandStateStatus]=0,GETDATE(),[DemandStatusChangeDate]),
[TakeLookLastMonthNum] = IIF([DemandStateStatus]=0,0,[TakeLookLastMonthNum]),
[VisitLastMonthNum] = IIF([DemandStateStatus]=0,0,[VisitLastMonthNum])
WHERE CustomerId = #{customerId} AND DeleteFlag = 0
case when 多条件编写方法
case when多条件编写语法:
case
when 条件1 and 条件2 then ‘1’
when 条件1 and 条件2 then ‘1’
else
end
**case when 多条件编写举例 **
create table [maomao365.com]
(keyId int identity,
xingBie varchar(100)
)
go
insert into [maomao365.com]
(xingbie)values('1'),
('0'),('1')
,('1'),('2')
go
select
keyId,
case
when xingBie ='1' or xingBie ='2'
then N'性别'
when xingBie ='0'
then N'未填写!'
else ''
end as xingBie
from [maomao365.com]
go
truncate table [maomao365.com]
drop table [maomao365.com]
下一篇: 用jquery实现遮罩层