Select ctot,invtot-amt as tmp, amt,invnbr,invdate,invcur,invcus,invtot from ((chspf032 left join (select rcptinv,sum(amtpaid) as amt from chspf0311 left join chspf031 on chspf0311.rcptnbr=chspf031.rcptnbr where rcptdate<=20151231 and (rcptsts is null or rcptsts <> 'C') group by rcptinv ) as x on chspf032.invnbr= x.rcptinv ) left join (select cnoteinv, sum(cnotetot) as ctot from chspf041 where (cnotests is null or cnotests <> 'C') and cnotedate <=20151231 group by cnoteinv) as y on chspf032.invnbr=y.cnoteinv ) where invsts <> 'C' and invcus='CE001'