Hi,
Try this:
SELECT T2.[ItemCode], T2.[WhsCode],sum(T1.[Quantity]), T2.[OnHand], sum( T1.[Quantity]) - T2.[OnHand] as diff FROM OITM T0 INNER JOIN OIBT T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITW T2 ON T0.ItemCode = T2.ItemCode WHERE T1.[WhsCode] = T2.[WhsCode] GROUP BY T2.[ItemCode], T2.[WhsCode],T2.[OnHand]
Let me know the query result.
Thanks & Regards,
Nagarajan