------解决方案-------------------- select case when 性别 = 1 then '男' when 性别 = 2 then '女' else '不男不女' end from tb
------解决方案-------------------- select case when 字段=1 then '男' else '女' from tb
------解决方案--------------------
SQL code
if object_id('people') is not null
drop table people
go
create table people(ID int, Sex int)
go
insert into people
select 1, 1 union all
select 2, 1 union all
select 3, 2 union all
select 4, 2
go
select ID, Sex=(case Sex
when 1 then '男'
when 2 then '女'
else ''
end)
from people
/*
ID Sex
----------- ----
1 男
2 男
3 女
4 女
*/
------解决方案--------------------
------解决方案-------------------- select case when 1 then 男 else 女 end from tb
------解决方案--------------------
------解决方案-------------------- select case when 性别 = 1 then '男' when 性别 = 2 then '女' else '待定' end from tb
------解决方案-------------------- case 性别 when 1 then '男' when 2 then '女' end
------解决方案--------------------