mssql sqlserver 如何编写case when 多条件呢?

摘要:
下文讲述case when中多条件的编写方法,如下所示:
实验环境:sql server 2008 r2  
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]

 

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐