当前位置: 代码迷 >> Sql Server >> Bit 判断男女解决方案
  详细解决方案

Bit 判断男女解决方案

热度:354   发布时间:2016-04-27 10:52:18.0
Bit 判断男女
create table aa
(Sid int not null primary key,
name char(8) not null ,
sex bit ?
)
请问在字段sex 那里怎么定义当 1:男 0:女

------解决方案--------------------
bit就两个值:1和0,你怎么定义男女??
你可以查询的时候用case when then else end来判断
------解决方案--------------------

只能在查询的时候定义
select case when sex=1 then '男' else '女' end 性别 from aa

------解决方案--------------------
在程序里判断的。


select case sex when 1 then '男' when 0 then '女' end as 性别 from #aa
------解决方案--------------------
SQL code
select case when sex=1 then '男' else '女' end 性别 from aa
------解决方案--------------------
晕,1和0不要硬性指定,在程序端或者sql语句查询的时候才解释出来。不然你使用bit就没有意义了。
  相关解决方案