Requiero hacer un reporte del inventario con numero de lotes totales y stock, hice la consulta y me repite los resultados.
Me podrian ayudar?, les dejo la query
Me podrian ayudar con este reporte:
SELECT T0.ItemCode, T1.ItemName, Count(T0.BatchNum), T0.WhsCode, T2.WhsName, ISNULL((SELECT SUM(Y.Quantity) FROM IBT1 Y
WHERE Y.ItemCode = T0.ItemCode AND Y.WhsCode = T0.WhsCode AND Y.BatchNum = T0.BatchNum AND Y.Direction != '1' AND Y.DocDate <= '[%0]'),0)-ISNULL((SELECT SUM(Y.Quantity) FROM IBT1 Y WHERE Y.ItemCode = T0.ItemCode AND Y.WhsCode = T0.WhsCode AND Y.BatchNum = T0.BatchNum AND Y.Direction = '1' AND Y.DocDate <= '[%0]'),0) 'Stock'
FROM IBT1 T0
INNER JOIN OITM T1 ON T1.ItemCode = T0.ItemCode
INNER JOIN OWHS T2 ON T2.WhsCode = T0.WhsCode
GROUP BY T0.ItemCode, T1.ItemName, T0.WhsCode, T2.WhsName, T0.BatchNum
Hola LMad, aunque un poco tarde, espero que te sea de utilidad este pequeño codigo, saludos!!
SELECT
T0.DistNumber,
T2.ItemCode,
T2.ItemName,
T1.OnHandQty,
(SELECT SUM(T100.Quantity) FROM OBTQ T100 WHERE T100.ItemCode=T2.ItemCode AND T100.WhsCode=T1.WhsCode) AS 'STOCK ALMACEN',
(SELECT SUM(T100.Quantity) FROM OBTQ T100 WHERE T100.ItemCode=T2.ItemCode) AS 'STOCK GLOBAL',
T1.WhsCode,
T3.WhsName
FROM OBTN T0
INNER JOIN OBBQ T1 ON T0.AbsEntry = T1.SnBMDAbs
INNER JOIN OITM T2 ON T0.ItemCode = T2.ItemCode
INNER JOIN OWHS T3 ON T1.WhsCode = T3.WhsCode
WHERE T1.OnHandQty>0
ORDER BY T1.ItemCode