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

Re: Query based on sales analysis

$
0
0

Hi,

 

Try this to start with:

 

SELECT T.ItemCode, T.ItemName, SUM(T.turnover) as Turnover, SUM(QTY) AS QTY

FROM

(SELECT

 

 

T1.ItemCode, T1.ItemName,  (T0.Price * T0.Quantity) AS turnover,(T0.Quantity) AS QTY,

(IsNull(T0.LineTotal,0)) 'Sales Amt',

(IsNull(T0.GrssProfit,0)) 'Gross Profit',

Case WHEN (Isnull(T0.LineTotal,0)) = 0 THEN 0 ELSE

IsNUll(T0.GrssProfit,0)/T0.LineTotal * 100 END 'Gross Profit %'

 

FROM INV1 T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITB T2 ON T2.ItmsGrpCod = T1.ItmsGrpCod INNER JOIN OINV T3 ON T3.DocEntry = T0.DocEntry INNER JOIN OCRD T4 ON T1.CardCode = T4.CardCode INNER JOIN OCRG T5 ON T4.GroupCode = T5.GroupCode

 

WHERE T3.DocDate Between [%1] AND [%2]

 

 

 

UNION ALL

 

SELECT

 

 

T1.ItemCode, T1.ItemName, (-T0.Price * T0.Quantity) AS turnover,(-T0.Quantity) AS QTY,

(IsNull(-T0.LineTotal,0)) 'Sales Amt',

(IsNull(-T0.GrssProfit,0)) 'Gross Profit',

Case WHEN (Isnull(T0.LineTotal,0)) = 0 THEN 0 ELSE

IsNUll(T0.GrssProfit,0)/T0.LineTotal * 100 END 'Gross Profit %'

 

FROM RIN1 T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITB T2 ON T2.ItmsGrpCod = T1.ItmsGrpCod INNER JOIN ORIN T3 ON T3.DocEntry = T0.DocEntry INNER JOIN OCRD T4 ON T1.CardCode = T4.CardCode INNER JOIN OCRG T5 ON T4.GroupCode = T5.GroupCode

 

WHERE T3.DocDate Between [%1] AND [%2]

) T

GROUP BY T.ItemCode, T.ItemName

 

Once it worked, you can add the other columns easily.

 

Thanks,

Gordon


Viewing all articles
Browse latest Browse all 9159

Trending Articles



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