Quantcast
Channel: SCN: Message List - Reporting and Printing
Viewing all articles
Browse latest Browse all 2719

Re: Query vs Sales Analysis Report

$
0
0

Hi Nagarajan,

 

Im user of Sap Business One, i need the completly query for obtain the Sales Analysis Report

 

i have this but in some items dont match

 

SELECT  ItemCode,   

        Sum(TotFac) - SUM(TotNC) as  'FacturadoNeto',   

        Sum(GBrutaFac)-SUM(GbrutaNC) as  'GBruta',   

        Round((Sum(GBrutaFac)-SUM(GbrutaNC))/case when  (Sum(TotFac) - SUM(TotNC))= 0 then 1 else (Sum(TotFac) - SUM(TotNC)) end  *100,2) as '% Margen'   

FROM (   

SELECT    

ItemCode = T1.ItemCode, 

Marca = (Select T2.FirmName from OMRC T2 JOIN OITM T3 on T2.FirmCode = T3.FirmCode where T3.ItemCode=T1.Itemcode), 

TotFac = Sum(T1.Linetotal),    

GBrutaFac = SUM(T1.GrssProfit),   

TotNc= 0,   

GbrutaNC = 0   

FROM OINV T0 (NOLOCK) INNER JOIN INV1 T1 (NOLOCK) ON T0.DocEntry = T1.DocEntry                                    

WHERE (T0.[DocDate] >='20140101' AND  T0.[DocDate] <='20141231') 

  and T0.DocType  = 'I' -- solo facturas por articulos   

Group by  T1.ItemCode  

Union   

SELECT    

ItemCode = T1.ItemCode,   

Marca = (Select T2.FirmName from OMRC T2 JOIN OITM T3 on T2.FirmCode = T3.FirmCode where T3.ItemCode=T1.Itemcode), 

TotFac = 0,   

GBrutaFac = 0,   

TotNc= Sum(T1.LineTotal),    

GbrutaNC = SUM(T1.GrssProfit)   

FROM ORIN T0 (NOLOCK) INNER JOIN RIN1 T1 (NOLOCK) ON T0.DocEntry = T1.DocEntry                                    

WHERE (T0.[DocDate] >='20140101' AND  T0.[DocDate] <='20141231')

  and T0.DocType  = 'I' -- solo NC por articulos   

Group by T1.ItemCode 

Union

SELECT    

ItemCode = T1.ItemCode,   

Marca = (Select T2.FirmName from OMRC T2 JOIN OITM T3 on T2.FirmCode = T3.FirmCode where T3.ItemCode=T1.Itemcode), 

TotFac = 0,   

GBrutaFac = 0,   

TotNc= Sum(T1.LineTotal),    

GbrutaNC = SUM(T1.GrssProfit)   

FROM ODPI T0 (NOLOCK) INNER JOIN DPI1 T1 (NOLOCK) ON T0.DocEntry = T1.DocEntry                                    

WHERE (T0.[DocDate] >='20140101' AND  T0.[DocDate] <='20141231')     

  and T0.DocType  = 'I' -- solo Fact Anticipos por articulos   

Group by T1.ItemCode

) T   

Group by  ItemCode, Marca


Viewing all articles
Browse latest Browse all 2719

Trending Articles



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