SQL isNull 小记

有个查询要用进行判断值为null,开始写了个SQL
update pro_productiontable set productionqty=productionqty-
(select storageqty = case 
					 When storageqty is null then 0
					 else storageqty 
					 end					 
					 from pro_storagetable where orderid='01020120729038'  and productionid=10684) Where productionid=10684
					 

结果显示的就是为null不能按我的想法显示0.无语了。在QQ群中有人提议使用isnull查了下用法,就改成下面的SQL

select ISNULL(storageqty,0) as storageqty  
 from pro_storagetable where orderid='01020120729038'  and productionid=10686

可惜了朋友的推荐,但结果是一样的没有达成要求。

后面在网上查了下isnull相关的记录,还是在CSDN找到了答案:

http://topic.csdn.net/u/20110324/22/C29117B0-B248-4330-9BD1-A84883C6410F.html

ssp2009 回复于:2011-03-25 00:01:50
ssp2009
引用 7 楼 lanyanse0504 的回复:
引用 5 楼 orchidcat 的回复:
因为学生ID 3 根本就没有对应couid=2,3的数据。

可以在外边加上Isnull((SELECT isnull(point,0) FROM score WHERE score.stuid=t.stuid AND couid=2) ,0)


point没有对应数据不就应该是null吗
为什么放在里面isnull(point,0)这样……

没有数据就是一行都没有,跟null是两个概念,null只存在某一行的某个字段里。
再次修改SQL

update pro_productiontable set productionqty=productionqty-
(select  isnull((select storageqty from pro_storagetable where orderid='01020120729038'  and productionid=10687),0)
 ) Where productionid=10684


搞定。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值