Quantcast
Channel: SCN : Unanswered Discussions - SAP on SQL Server
Viewing all articles
Browse latest Browse all 519

Profit and Loss Statement

$
0
0

Hi all,

 

I am trying to recreate the results of the Profit and Loss Statement so I can customize them for a user as they need to sort sales by customer group and territory. I have created a query but the trouble is that it doesn't seem to return the same value as the P&L statement. Are there any conditions I'm missing here?

 

This is my query:

 

SELECT GroupName [Group], Descript [Territory], SUM(Total) [Invoiced] FROM (

 

--Invoices

SELECT T2.[GroupName], T3.[descript], SUM(T0.[DocTotal]) [Total] FROM OINV T0 LEFT JOIN OCRD T1 ON T0.CardCode = T1.CardCode LEFT JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode LEFT JOIN OTER T3 ON T1.Territory = T3.territryID WHERE T0.DocDate >= '20130701' AND T0.DocDate <= '20140630' GROUP BY T2.[GroupName], T3.[descript]

 

UNION ALL

 

--Credits

SELECT T2.[GroupName], T3.[descript], SUM(T0.[DocTotal]) * -1 [Total] FROM ORIN T0 LEFT JOIN OCRD T1 ON T0.CardCode = T1.CardCode LEFT JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode LEFT JOIN OTER T3 ON T1.Territory = T3.territryID WHERE T0.DocDate >= '20130701' AND T0.DocDate <= '20140630' GROUP BY T2.[GroupName], T3.[descript]

 

) T GROUP BY GroupName, Descript ORDER BY GroupName, Descript


Viewing all articles
Browse latest Browse all 519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>