读书人

这个sql 语句如何写

发布时间: 2012-02-02 23:57:14 作者: rapoo

这个sql 语句怎么写?
我要插入bit 型数据

前台接受到的是 true 和false

我用insert into 语句插入
怎么判段 如果为true 则插入 1 ,

flase 则插入0

[解决办法]

SQL code
--这个程序里插入前判断下就行了吧。。。
[解决办法]
SQL code
insert into tb select case col when 'ture' then 1 when 'flase' then 0 end from ...
[解决办法]
这要看前台与语句的接口是什么了.
如果用存储过程,设置parameter参数为逻辑型的话,就不用变化.
如果前台用的是插入语句,那在前台直接改为1,0不是什么难事.
如果....

貌似没有如果了.前台要传数据来,总不能愚蠢到传一个 insert into tb(bitcol)values('true')进来吧!
[解决办法]
探讨
SQL code

insert into tb select case col when 'ture' then 1 when 'flase' then 0 end from ...

[解决办法]
SQL code
declare @tb table(istrue bit)insert into @tb select 'true'select * from @tb/*(1 行受影响)istrue------1
[解决办法]
前台接受到的是 true 和false

你前端变量是布尔型的直接判断插入呗!SQL05中,字段是bit型,写入数据你打开表看还是会显示 true 或 false,这没什么可纠结的。
[解决办法]
bit类型本身就是true和false,直管insert就行了
[解决办法]
case when 即可。
[解决办法]
探讨
引用:
SQL code

insert into tb select case col when 'ture' then 1 when 'flase' then 0 end from ...


试问,这句语句写在哪儿呢?

[解决办法]
探讨
bit类型本身就是true和false,直管insert就行了

[解决办法]
SQL code
if object_id('tb','U') is not null   drop table tbgocreate table tb( id int identity(1,1), name varchar(10), sex bit)go--字符串值 TRUE 和 FALSE 可以转换为以下 bit 值:TRUE 转换为 1,FALSE 转换为 0。 insert into tb(name,sex)select '张三','true' union allselect '李四','true' union allselect '王五','false'goselect * from tb/*id          name       sex----------- ---------- -----1           张三         12           李四         13           王五         0(3 行受影响)*/
[解决办法]
学习了,很好的例子
[解决办法]
不知所云
[解决办法]
+1
探讨
SQL code
insert into tb select case col when 'ture' then 1 when 'flase' then 0 end from ...

读书人网 >SQL Server

热点推荐