--那就是这个意思了?? update sz_bj set scbj=case when scbj is null then 0 else 1 end where bjid=103
--scbj 的值为0或NULL的改为1,怎么实现?? -- update sz_bj set scbj=case when ( (scbj is null) or (scbj=0) ) then 1 end where bjid=103
显示isnull(scbj,0)不能做为左值, 所以是不能运行的. 楼主要做什么? 当bjid为103时,scbj赋什么值? 是不是scbj为null时,赋值为0;不为null时,赋值为1? 如果是这样的话,下面的方法就可以了 update sz_bj set scbj=case when scbj is null then 0 else 1 end where bjid=103
/*回帖时,没看到上面的那些留言. 如果要求是:"scbj是NULL的时候用0代替, 然后将scbj update 为1"的话,下面的就可以。 楼上的,为什么要把where子句的限制条件,放在set子句里啊。 那不是很麻烦吗? */ update sz_bj set scbj=1 where bjid=103 and (scbj is null or scbj=0)
update sz_bj set scbj=1 where bjid=103 and (scbj is null or scbj=0)或者 update sz_bj set scbj=(case when (scbj is null or scbj=0) then 1 else scbj end) where bjid=103
update sz_bj set scbj=case when scbj is null then 0 else 1 end where bjid=103 是这样的吧。
--filebat(Mark) update sz_bj set scbj=1 where bjid=103 and (scbj is null or scbj=0) 发现现在写SQL 好象有点思维定势了 -.- 呵呵
楼主的说法有点矛盾,,,是先后顺序,还是同时顺序,,是先把NULL替换为0,再替换为1,那还不如将字段为 null 的值替换为1update sz_bj set scbj=case when ( (scbj is null) or (scbj=0) ) then 1 end where bjid=103
update sz_bj set scbj=1 where bjid=103 and isnull(scbj,0)=0
update sz_bj set scbj=case when scbj is null then 0 else 1 end
where bjid=103
--
update sz_bj set scbj=case when ( (scbj is null) or (scbj=0) ) then 1 end
where bjid=103
楼主要做什么?
当bjid为103时,scbj赋什么值?
是不是scbj为null时,赋值为0;不为null时,赋值为1?
如果是这样的话,下面的方法就可以了
update sz_bj
set scbj=case when scbj is null then 0 else 1 end
where bjid=103
如果要求是:"scbj是NULL的时候用0代替,
然后将scbj update 为1"的话,下面的就可以。
楼上的,为什么要把where子句的限制条件,放在set子句里啊。
那不是很麻烦吗?
*/
update sz_bj
set scbj=1
where bjid=103
and (scbj is null or scbj=0)
set scbj=1
where bjid=103 and
(scbj is null or scbj=0)或者
update sz_bj
set scbj=(case when (scbj is null or scbj=0) then 1 else scbj end)
where bjid=103
where bjid=103
是这样的吧。
update sz_bj
set scbj=1
where bjid=103
and (scbj is null or scbj=0)
发现现在写SQL 好象有点思维定势了 -.- 呵呵
null 的值替换为1update sz_bj set scbj=case when ( (scbj is null) or (scbj=0) ) then 1 end
where bjid=103