Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Code working fine, just need to replace laste line to be:

IF IS null then 0


Some help

What I have tried:

SQL
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 
Posted
Updated 3-Sep-18 6:37am
v3
Comments
[no name] 2-Sep-18 9:06am    
Don't get the Point nor I see a question. Do you mean "where x2.roba is not null " with last line?

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
SQL
where coalesce(x2.roba, 0) = 0
 
Share this answer
 
Comments
Goran Bibic 2-Sep-18 9:15am    
Thank you
If you are using TSQL you could use IsNull
SQL
where isnull(x2.roba, 0) = 0
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900