forecast_api/build/snap_cost_current.sql

44 lines
871 B
MySQL
Raw Permalink Normal View History

2020-02-21 11:16:05 -05:00
BEGIN;
WITH
plist AS (
SELECT DISTINCT
part
,plnt
FROM
2023-03-01 16:07:36 -05:00
rlarp.osmf
-----prevent a list of fake parts
INNER JOIN lgdat.stka ON
v6part = part
AND v6plnt = plnt
2020-02-21 11:16:05 -05:00
)
,clist AS (
SELECT
p.part
,p.plnt
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs) stdcost
FROM
plist p
LEFT OUTER JOIN lgdat.icstm im ON
im.cgpart = p.part
AND im.cgplnt = p.plnt
LEFT OUTER JOIN lgdat.icstp ip ON
ip.chpart = p.part
AND ip.chplnt = p.plnt
LEFT OUTER JOIN lgdat.icstr ir ON
ir.y0part = p.part
AND ir.y0plnt = p.plnt
)
UPDATE
2023-03-01 16:07:36 -05:00
rlarp.osmf o
2020-02-21 11:16:05 -05:00
SET
fb_cst_loc_cur = c.stdcost * o.fb_qty
FROM
clist c
WHERE
c.part = o.part
AND c.plnt = o.plnt;
--AND version = 'b21';
2020-02-21 11:16:05 -05:00
2023-03-01 16:07:36 -05:00
commit;