Thanks Kennedy, yeah that does fix the bug using the OITW table. However, when i call values of OnHand, IsCommited and OnOrder, it displays quantities for one specific warehouse only. any ideas on how to get it to display the total quantities (all warehouses combined)?
I think i have to use a 'Union All' here somewhere... In my last attempt I used the OITM table, which displays correct values of OnHand, IsCommited and OnOrder already. The only problem is some items are displayed twice with different values in the 'Quantity' column. The correct value is the sum of those two quantities.
My Query is as follows:
SELECT T1.[ItemCode], T1.[Dscription], sum(T1.[Quantity]) as 'Quantity', T3.[OnHand] as 'On Hand', T3.[IsCommited] as 'Committed', T3.[OnOrder] as 'Ordered'
FROM [dbo].[OINV] T0 INNER JOIN [dbo].[INV1] T1 ON T0.DocEntry = T1.DocEntry INNER JOIN [dbo].[OITM] T3 ON T1.ItemCode = T3.ItemCode
WHERE T0.[DocDate] >= '06.01.12'
AND T0.[DocDate] <= '06.30.12'
AND T0.[CardCode] = 'C00081'
AND T1.[TargetType] NOT Like '14'
GROUP BY T1.[ItemCode], T1.[Dscription], T1.[Quantity], T3.[OnHand], T3.[IsCommited], T3.[OnOrder]
ORDER BY T1.[ItemCode]