use replacement part in all cases, and apply currency

This commit is contained in:
Paul Trowbridge 2019-04-16 18:50:01 -04:00
parent 82b0b10dfb
commit cd53505d59

View File

@ -5,7 +5,7 @@ repl AS (
SELECT * FROM SELECT * FROM
( (
VALUES VALUES
('IFA06000G181012LRCIR ','IFA06000G181012LRCIR') ('MOW24000A47E880','MOW24000A47E880')
) as x(orig,fix) ) as x(orig,fix)
) )
,SEG AS ( ,SEG AS (
@ -146,10 +146,10 @@ SELECT
,COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) stdcost ,COALESCE(cm.cgstcs, cp.chstcs, cr.y0stcs) stdcost
,copr.curr c_currency ,copr.curr c_currency
,cx.rate c_rate ,cx.rate c_rate
,SUBSTR(o.part,1,3)||coalesce(' - '||F.DESCR,'') part_family ,SUBSTR(repl.fix,1,3)||coalesce(' - '||F.DESCR,'') part_family
,SUBSTRING(o.part,1,8)||coalesce(' - '||MD.DESCR,'') part_group ,SUBSTRING(repl.fix,1,8)||coalesce(' - '||MD.DESCR,'') part_group
,COALESCE(MG.GRP,'Unbranded') branding ,COALESCE(MG.GRP,'Unbranded') branding
,CASE WHEN substring(COALESCE(m.avgled, p.awgled),1,1) <= '2' THEN SUBSTRING(o.part,9,3) ELSE '' END color ,CASE WHEN substring(COALESCE(m.avgled, p.awgled),1,1) <= '2' THEN SUBSTRING(repl.fix,9,3) ELSE '' END color
,COALESCE(SEG.SEGM,'Other') segm ,COALESCE(SEG.SEGM,'Other') segm
,COALESCE(m.avmajg,p.awmajg)||COALESCE(' - '||BQDES,'') majg_descr ,COALESCE(m.avmajg,p.awmajg)||COALESCE(' - '||BQDES,'') majg_descr
,COALESCE(m.avming,p.awming)||COALESCE(' - '||BRDES,'') ming_descr ,COALESCE(m.avming,p.awming)||COALESCE(' - '||BRDES,'') ming_descr
@ -217,12 +217,12 @@ FROM
SEG.GLEC = COALESCE(m.avgled,p.awgled) SEG.GLEC = COALESCE(m.avgled,p.awgled)
--AND SEG.SEGM <> 'Other' --AND SEG.SEGM <> 'Other'
LEFT OUTER JOIN MG ON LEFT OUTER JOIN MG ON
MG.F1 = SUBSTR(o.part,16,1) MG.F1 = SUBSTR(repl.fix,16,1)
AND MG.MING = COALESCE(m.avming,p.awming) AND MG.MING = COALESCE(m.avming,p.awming)
LEFT OUTER JOIN rlarp.family F ON LEFT OUTER JOIN rlarp.family F ON
F.F3 = SUBSTR(o.part,1,3) F.F3 = SUBSTR(repl.fix,1,3)
LEFT OUTER JOIN MD ON LEFT OUTER JOIN MD ON
MD.MOLD = SUBSTR(o.part,1,8) MD.MOLD = SUBSTR(repl.fix,1,8)
LEFT OUTER JOIN SI ON LEFT OUTER JOIN SI ON
SI.BSMJCD = COALESCE(m.avmajs,p.awmajs) SI.BSMJCD = COALESCE(m.avmajs,p.awmajs)
AND SI.BSMNCD = COALESCE(m.avmins,p.awmins) AND SI.BSMNCD = COALESCE(m.avmins,p.awmins)
@ -308,6 +308,10 @@ SET
,fb_cst_loc = o.fb_qty * x.stdcost ,fb_cst_loc = o.fb_qty * x.stdcost
,fb_cst_loc_cur = o.fb_qty * x.stdcost ,fb_cst_loc_cur = o.fb_qty * x.stdcost
,fb_cst_loc_fut = o.fb_qty * x.stdcost ,fb_cst_loc_fut = o.fb_qty * x.stdcost
,cost_loc = o.fb_qty * x.stdcost
,cost_usd = o.fb_qty * x.stdcost * x.c_rate
,c_currency = x.c_currency
,c_rate = x.c_rate
,part_family = x.part_family ,part_family = x.part_family
,part_group = x.part_group ,part_group = x.part_group
,branding = x.branding ,branding = x.branding
@ -329,4 +333,4 @@ RETURNING o.*
SELECT * FROM u; SELECT * FROM u;
--ROLLBACK; --ROLLBACK;
COMMIT; --COMMIT;