Hello Experts,
I am working on the query for Inventory Audit report, found out many queries, out of which i am trying to modify one query.
Here i am stuck an error which I am not able to solve. if you can kindly help me find out where the error is?
This query allows to get the inventory audit report with values. I have added the query below.
select T.ItmsGrpNam, T.ItemCode, T.ItemName, sum(T.OpeningQty) , sum(T.OpeningVal) ,
sum(T.InQty), sum(T.InVal), sum(T.OutQty) , sum(T.OutVal) , sum(T.ClosingQty),
sum(T.ClosingVal) from
(SELECT T2.ItmsGrpNam, T1.ItemCode, T1.ItemName, sum(T0.InQty - T0.OutQty) OpeningQty,
sum(case when T0.OutQty>0 then T0.TransValue else T0.TransValue end) OpeningVal, 0.00 InQty, 0.00 InVal, 0.00 OutQty, 0.00 OutVal,
0.00 ClosingQty, 0.00 ClosingVal FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITB T2 ON T1.ItmsGrpCod = T2.ItmsGrpCod
where T0.DocDate < [%0] and (T0.Warehouse = '[%1]' or '[%2]' = 'ALL') GROUP BY T2.ItmsGrpNam, T1.ItemCode, T1.ItemName)
union all
(SELECT T2.ItmsGrpNam, T1.ItemCode, T1.ItemName, 0.00, 0.00, sum(T0.InQty), sum(case when T0.OutQty>0 then 0.00
else T0.TransValue end), 0.00, 0.00, 0.00, 0.00 FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITB
T2 ON T1.ItmsGrpCod = T2.ItmsGrpCod where T0.DocDate >= [%0] and T0.DocDate <= [%3] and (T0.Warehouse = '[%1]' or '[%2]' = 'ALL')
GROUP BY T2.ItmsGrpNam, T1.ItemCode, T1.ItemName) union all
(SELECT T2.ItmsGrpNam, T1.ItemCode, T1.ItemName, 0.00, 0.00, 0.00, 0.00, sum(T0.OutQty), sum(case when T0.OutQty>0 then -1*T0.TransValue else 0.00 end), 0.00, 0.00 FROM OINM T0 INNER JOIN OITM T1 ON
T0.ItemCode = T1.ItemCode INNER JOIN OITB T2 ON T1.ItmsGrpCod = T2.ItmsGrpCod where T0.DocDate >= [%0] and T0.DocDate <= [%3] and
(T0.Warehouse = '[%1]' or '[%2]' = 'ALL') GROUP BY T2.ItmsGrpNam, T1.ItemCode, T1.ItemName) union all
(SELECT T2.ItmsGrpNam, T1.ItemCode, T1.ItemName, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, sum(T0.InQty - T0.OutQty), sum(case when T0.OutQty>0 then
T0.TransValue else T0.TransValue end) FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITB T2 ON
T1.ItmsGrpCod = T2.ItmsGrpCod where T0.DocDate <= [%3] and (T0.Warehouse = '[%1]' or '[%2]' = 'ALL') GROUP BY T2.ItmsGrpNam,
T1.ItemCode, T1.ItemName) T group by T.ItmsGrpNam, T.ItemCode, T.ItemName order by T.ItmsGrpNam, T.ItemCode, T.ItemName
Any suggestions will be helpful.
thanks in Advance.
Ravi.