34,875
社区成员
发帖
与我相关
我的任务
分享
select
case status
when 'Active' then 1
when 'Disable' then 0
end
from table1
---测试数据---
if object_id('[table1]') is not null drop table [table1]
go
create table [table1]([status] varchar(7))
insert [table1]
select 'Active' union all
select 'Disable' union all
select 'Disable' union all
select 'Active'
---查询---
select
case status when 'Active' then 1 when 'Disable' then 0 end
from
table1
---结果---
-----------
1
0
0
1
(所影响的行数为 4 行)select
case status when 'Active' then 1 when 'Disable' then 0 end
from
table1