如果为null则为0 SQL [英] If is null then 0 SQL

查看:356
本文介绍了如果为null则为0 SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码工作正常,只需要替换laste行为:



Code working fine, just need to replace laste line to be:

IF IS null then 0





一些帮助



我的尝试:





Some help

What I have tried:

select x1.naziv, x1.Nabavka, x2.Prodaja, x1.Nabavka-x2.Prodaja as 'Stanje' from (select naziv, sum(kolicina) as Nabavka from   
( select naziv as naziv, convert(float, kolicina) as kolicina from ulazni_racun_roba_roba union all select naziv as naziv, convert(float, kolicina) as kolicina from mp_ulazni_racun_ostalo_roba ) a   
group by naziv) x1 left join ( select roba, sum(kolicina) as Prodaja from   
( select roba, convert(float, kolicina) as kolicina from mp_racun_roba union all select roba, convert(float, kolicina) as kolicina from mp_faktura_roba ) b   
group by roba ) x2 on x1.naziv = x2.roba   
where x2.roba is not null 

推荐答案

不确定我是否正确理解了这个问题,但你的意思是,如果x2.roba为空,比较应该使用0吗?在这种情况下,考虑

Not sure if I understand the question correctly but do you mean hat the comparison should use 0 if x2.roba is null? In that case consider
where coalesce(x2.roba, 0) = 0


如果你使用的是TSQL,你可以使用IsNull

If you are using TSQL you could use IsNull
where isnull(x2.roba, 0) = 0


这篇关于如果为null则为0 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆