vara reddy

vara reddy

  • NA
  • 209
  • 0

subtracting two values from two tables when null value is present

Jun 21 2012 8:43 AM
Hi i had 3 tables with joining.
when i am subtracting a value from null value, the result was null, but it is not correct.

for a better understanding see the below image and query

select p.partnerid,
sum(case when c.amount is not null then c.amount else 0 end) as amount,
sum(case when c.netamt is not null then c.netamt else 0 end) as total,
sum(case when (c.netamt - d.paidamount) is not null then (c.netamt - d.paidamount) else 0 end) as remainingamount,
sum(case when d.paidamount is not null then d.paidamount else 0 end) as paidamt

from customerinfo c
left join dailypayments d on c.accno = d.accno
right join partnerinfo p on c.partnerid = p.partnerid
where (d.paiddate is null or (d.paiddate >= '2011-3-15' and d.paiddate <= '2012-6-13')) and  p.manager = 7 group by p.partnerid



Answers (1)