求一SQL语句

txjstar 2009-05-15 10:59:35
不知道怎么写,所以求助各位,是这样的

某表中状态字段(varchar)只有两个值Active和Disable,想查询的时候显示结果为1和0.

select status from table1
--------------------------
Active
Disable
Disable
Active

查询语句如果在不改变原记录的情况下执行出以下查询结果
---------------------
1
0
0
1


谢谢各位拉
...全文
50 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
txjstar 2009-05-15
  • 打赏
  • 举报
回复
问题解决了,谢谢一楼,也谢谢二楼
--小F-- 2009-05-15
  • 打赏
  • 举报
回复
--Try

select
case status
when 'Active' then 1
when 'Disable' then 0
end
from table1
百年树人 2009-05-15
  • 打赏
  • 举报
回复
---测试数据---
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 行)
百年树人 2009-05-15
  • 打赏
  • 举报
回复
select 
case status when 'Active' then 1 when 'Disable' then 0 end
from
table1

34,875

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧