Tuesday, March 15, 2011

JD Edwards fix onhand quantity in F41021 from F4111

SELECT a.LOCN,a.MCU,a.ITM,PQOH,TRQT into zdev.dbo.temp_pqoh
FROM
(SELECT MCU=LTRIM(RTRIM(LIMCU)),ITM=CAST(LIITM as INT),PQOH=SUM(LIPQOH),LOCN=LILOCN
   FROM JDE_PRODUCTION.PRODDTA.F41021
   GROUP BY LIMCU,LILOCN, LIITM) a INNER JOIN
       (SELECT LOCN=ILLOCN, MCU=LTRIM(RTRIM(ILMCU)),ITM=CAST(ILITM as INT),TRQT=SUM(ILTRQT)
               FROM JDE_PRODUCTION.PRODDTA.F4111
                        GROUP BY ILMCU,ILLOCN,ILITM) b ON a.ITM=b.ITM AND a.MCU=b.MCU and a.LOCN=b.LOCN
                        WHERE PQOH!=TRQT
                             ORDER BY 1,2

select * from zdev.dbo.temp_pqoh

--drop table zdev.dbo.temp_pqoh
select lipqoh,TRQT,liitm,itm,lilocn,locn
--UPDATE proddta.f41021 SET lipqoh =trqt
from proddta.f41021
INNER JOIN zdev.dbo.temp_pqoh  on liITM=itm and rtrim(ltrim(limcu))=rtrim(ltrim(mcu)) and lilocn=locn
where rtrim(ltrim(limcu))=rtrim(ltrim(mcu)) and liITM=itm  and lilocn=locn and
rtrim(ltrim(limcu))=rtrim(ltrim(mcu)) and lipqoh<>trqt
 

 

No comments: