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

Re: Query Analysis Report for ordering

$
0
0

Hi this query may help you.

 

 

Remove the join to OITW as this duplicates you records causing wrong quantity values.

 

 

Use subquery to calculate OnHand quantity.

 

 

Remove group by currency, also causes duplicates.

 

 

SELECT

T2.[U_AITMCode] as 'ACode',

T1.ItemCode as 'CSS Code',

T2.ItemName,

T4.[ItmsGrpNam] as 'SS Group',

T2.[U_AGRP] as 'AJT Group',

T2.[BuyUnitMsr] as 'UOM',

(select sum(onHandQty) from OIBQ where WhsCode  not in ('03','04','06','07') and itemcode = t1.itemcode) as 'SS Stock',

T2.[IsCommited] as 'Committed',

T2.[OnOrder] as 'On Way',

(select sum(onHandQty) from OIBQ where WhsCode  not in ('03','04','06','07') and itemcode = t1.itemcode) + t2.onorder as 'Total Stock',

((select sum(onHandQty) from OIBQ where WhsCode  not in ('03','04','06','07') and itemcode = t1.itemcode) + t2.onorder) - t2.IsCommited As 'Availability',

T2.[U_AStock] As 'AStock',

T2.[U_ATransit],

(T2.[U_AStock]+T2.[U_ATransit]) as 'ATotal',

(((select sum(onHandQty) from OIBQ where WhsCode  not in ('03','04','06','07') and itemcode = t1.itemcode)

  +T2.[OnOrder])+(T2.[U_AStock]+T2.[U_ATransit])) As 'StockingQty',

cast(sum(T1.Quantity) as numeric) as 'Quantity Sold',

Avg(T1.Quantity) As 'Average',

Round(Avg(T1.Quantity),0) As 'Avg. Value',

(Round(Avg(T1.Quantity),0)*3) as 'X3',

Max(T1.Quantity) As 'Maximum',

(Max(T1.Quantity)*3) as 'X3',

T2.[U_ASP] as 'Selling  Price',

T2.[BVolume] as 'Volume'

 

 

 

 

FROM

  dbo.INV1 T1

  inner join OINV T3 on T1.docentry = t3.docentry

  LEFT OUTER JOIN OITM T2 on T1.ItemCode = T2.ItemCode

  INNER JOIN OITB T4 ON T4.ItmsGrpCod = T2.ItmsGrpCod

 

 

 

WHERE 

  t3.docdate between [%0] and [%1] And t2.validFor = 'Y'

 

 

 

 

GROUP BY

  T1.ItemCode, T2.ItemName, T4.[ItmsGrpNam],T2.OnHand,

  T2.[IsCommited], T2.[OnOrder], T2.[U_ATransit],[U_ASP],T2.[BuyUnitMsr],

  T2.[BVolume],T2.[U_AITMCode],T2.[U_AGRP],T2.[U_AStock],T2.[U_AJTBPrice]

 

 

 

 

ORDER BY

  sum(T1.Quantity) desc


Viewing all articles
Browse latest Browse all 3575

Trending Articles