首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

Bit 判断男女解决方案

2012-10-21 
Bit 判断男女create table aa(Sid int not null primary key,name char(8) not null ,sex bit ?)请问在字

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就没有意义了。

热点排行
Bad Request.