Skip to Content
0
Jul 20, 2020 at 10:55 PM

Total cumulative in the IOMN

65 Views

Hi,

Guys, I crashed in a cumulative calculation being in the OINM table.
Although there is a lot of information on the forum on the subject, I haven't been able to resolve this issue yet and with that I ask for your help.
The question is:
I need to calculate (T2. "InQty" - T2. "OutQty") with this bringing me the calculated value and in the following lines If:
Input = SUM
Output = Subtract

I saw in some post that you need to declare (@declare) but I still lack experience.

T2."DocDate", T4."WhsCode", T3."WhsName", T0."ItmsGrpNam",T1."ItemCode", T1."ItemName",
T1."InvntryUom",(T2."InQty") AS "Qtd In",(T2."OutQty") AS "Qtd Out", AVG((T2."InQty") - (T2."OutQty")) As "Total Stock", T1."U_RSD_PesoBruto", T1."U_RSD_UN_Conversao", 
AVG(t2."Price") AS "Price"

FROM OITB T0     
INNER JOIN OITM T1 ON T1."ItmsGrpCod" = T0."ItmsGrpCod" 
INNER JOIN OINM T2 ON T2."ItemCode" = T1."ItemCode"
INNER JOIN OWHS T3 ON T3."WhsCode" = T2."Warehouse" 
INNER JOIN OITW T4 ON T4."WhsCode" = T3."WhsCode"
--INNER JOIN OITW T5 ON T5."ItemCode" = T2."ItemCode" 

WHERE 
T2."TransType" in (13,14,15,16,18,19,20,59,60,67,69,162,310000001) AND
T1."ItemCode" = '[%0]' 

GROUP BY T2."TransType",T2."DocDate",T4."WhsCode",T3."WhsName", T1."ItemCode", T1."ItemName",
T0."ItmsGrpNam", T1."InvntryUom",T1."U_RSD_PesoBruto", T1."U_RSD_UN_Conversao", T2."InQty",T2."OutQty"

Order by T2."DocDate"