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]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM