Dear All
I created a query to get results but i cant get my desire results in below mention query show me the sum of A/R Down Payment Invoices total and against AR invoices sum total and less credit note which are based on AR invoices only but i need all credit notes less if it is based on AR invoice or A/R Down Payment Invoices , my query did not less the that credit note which are based on A/R Down Payment Invoices. please Help.
SELECT
T0.cardcode,T0.cardname,Sum(T0.DocTotal ) as DownPayments,Sum(T .DrawnSum) as Invoices ,SUM(T1.DrawnSum) as [Credit Notes],
Sum(T0.DocTotal )-isnull(Sum(T .DrawnSum) ,0)+ISNULL(SUM(T1.DrawnSum),0) as 'OutStanding'
FROM ODPI T0
LEFT OUTER JOIN (Select INV9 .BaseAbs ,SUM(INV9 .DrawnSum) as[DrawnSum] from INV9 group by INV9 .BaseAbs ) T on T0 .DocEntry = T.BaseAbs
LEFT OUTER JOIN (Select RIN9 .BaseAbs ,SUM(RIN9 .DrawnSum) as[DrawnSum] from RIN9 group by RIN9 .BaseAbs ) T1 on T0 .DocEntry = T1.BaseAbs'
Group By T0.cardcode,T0.cardname
having Sum(T0.DocTotal )-isnull(Sum(T .DrawnSum) ,0)+ISNULL(SUM(T1.DrawnSum),0) <> 0