Hi Experts. I have this following query working to see the current stocks in SAP and quantity sold, say last one year. the problem i have here is, if there is no invoice for a particular SKU during given timeframe then this report doesn't fetch the data of that SKU. I tried even ISNULL to fetch that but certainly missing something. please advise.
here is the query:
Select A.[ItemCode], A.[ItemName] [itemDescription], A.[OnHand] [In Stock], A.[IsCommited], A.[OnOrder] [Ordered], ((A.[OnHand] - A.[IsCommited]) + A.OnOrder) [Available], SUM(A.Quantity) [Quantity Sold], A.[Price]
From(
SELECT
T2.[ItemCode], T2.[ItemName], isnull(T4.[OnHand],0) as 'OnHand', T4.[IsCommited], T4.[OnOrder],
ISNULL(SUM(T1.[Quantity]),0) as 'Quantity', T3.[Price]
FROM
OINV T0 INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry] INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode] INNER JOIN ITM1 T3 ON T2.[ItemCode] = T3.[ItemCode] INNER JOIN OITW T4 ON T2.[ItemCode] = T4.[ItemCode] INNER JOIN OMRC T5 ON T2.[FirmCode] = T5.[FirmCode]
WHERE
T0.[CANCELED] = 'N' and
T0.[DocDate] >=[%0] and
T0.[DocDate] <=[%1] and
T5.[FirmName] = 'ABC' and
T3.[PriceList] = '2' and
T4.[WhsCode] = '100'
Group by
T2.[ItemCode], T2.[ItemName], T4.[OnHand],T4.[IsCommited], T4.[OnOrder], T3.[Price]
Union all
SELECT
T2.[ItemCode], T2.[ItemName], isnull(T4.[OnHand],0) as 'OnHand', T4.[IsCommited], T4.[OnOrder], ISNULL(SUM(T1.[Quantity])*-1,0) as 'Quantity', T3.[Price]
FROM
ORIN T0 INNER JOIN RIN1 T1 ON T0.[DocEntry] = T1.[DocEntry] INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode] INNER JOIN ITM1 T3 ON T2.[ItemCode] = T3.[ItemCode] INNER JOIN OITW T4 ON T2.[ItemCode] = T4.[ItemCode] INNER JOIN OMRC T5 ON T2.[FirmCode] = T5.[FirmCode]
WHERE
T0.[CANCELED] = 'N' and
T0.[DocDate] >=[%0] and
T0.[DocDate] <=[%1] and
T5.[FirmName] = 'ABC' and
T3.[PriceList] = '2' and
T4.[WhsCode] = '100'
Group by
T2.[ItemCode],
T2.[ItemName], T4.[OnHand], T4.[IsCommited], T4.[OnOrder], T3.[Price] )A
Group by
A.[ItemCode], A.[ItemName], A.[OnHand], A.[IsCommited], A.[OnOrder], A.[Price]