Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3316

Re: Year on Year Comparison by Customer

$
0
0

Hi,

 

Try this query for easy comparison:

 

SELECT

[CustName] as CustName,[2011],[2012],[2013]

 

from

 

(SELECT

T0.[CardName] as CustName, sum(T1.[LineTotal]) as Total,

datepart(yy,T0.[DocDate]) as year FROM OINV T0 INNER JOIN INV1 T1 ON

T0.DocEntry = T1.DocEntry WHERE

T0.[CardCode] = 'cvet01' GROUP BY T0.[CardName],T0.[DocDate]

 

union all

 

(SELECT

T0.[CardName] as CustName, -sum(T1.[LineTotal]) as Total,

datepart(yy,T0.[DocDate]) as year FROM ORIN T0 INNER JOIN RIN1 T1 ON

T0.DocEntry = T1.DocEntry WHERE

T0.[CardCode] = 'cvet01'  GROUP BY T0.[CardName],T0.[DocDate])) S

 

Pivot (sum(S.total) For  YEAR IN ([2011],[2012],[2013])) P


Thank you

 


Viewing all articles
Browse latest Browse all 3316

Trending Articles