switch scale columns

This commit is contained in:
Trowbridge 2020-02-13 13:19:06 -05:00
parent 79ec4739c1
commit 9793596d27

View File

@ -103,16 +103,16 @@ target AS (select target_increment incr)
,scale AS ( ,scale AS (
SELECT SELECT
(SELECT incr::numeric FROM target) incr (SELECT incr::numeric FROM target) incr
,(SELECT sum(fb_val_loc * r_rate) FROM basemix) base ,(SELECT sum(value_loc * r_rate) FROM basemix) base
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM basemix) = 0 THEN ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN
0 0
ELSE ELSE
(SELECT incr::numeric FROM target)/(SELECT sum(fb_val_loc * r_rate) FROM basemix) (SELECT incr::numeric FROM target)/(SELECT sum(value_loc * r_rate) FROM basemix)
END factor END factor
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM basemix) = 0 THEN ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM basemix) = 0 THEN
CASE WHEN ((SELECT incr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM basemix)) <> 0 THEN CASE WHEN ((SELECT incr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM basemix)) <> 0 THEN
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply --if the base value is -0- but the target value hasn't been achieved, derive a price to apply
((SELECT incr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM basemix))/(SELECT sum(fb_qty) FROM basemix) ((SELECT incr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM basemix))/(SELECT sum(units) FROM basemix)
ELSE ELSE
0 0
END END
@ -182,14 +182,14 @@ SELECT
,b.ddqtsi --0 ,b.ddqtsi --0
,b.fgqshp --0 ,b.fgqshp --0
,b.diqtsh --0 ,b.diqtsh --0
,0 fb_qty ,0 units
,0 fb_cst_loc ,0 fb_cst_loc
,0 fb_cst_loc_cur ,0 fb_cst_loc_cur
,0 fb_cst_loc_fut ,0 fb_cst_loc_fut
--,b.fb_val_loc*s.factor fb_val_loc --,b.value_loc*s.factor value_loc
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric fb_val_loc ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc_pl*s.factor END)::numeric fb_val_loc_pl ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc_pl*s.factor END)::numeric value_loc_pl
--,b.fb_val_loc_pl*s.factor fb_val_loc_pl --,b.value_loc_pl*s.factor value_loc_pl
,b.calc_status --0 ,b.calc_status --0
,b.flag --0 ,b.flag --0
,b.orderdate ,b.orderdate
@ -227,8 +227,8 @@ SELECT
,b.mod_chansub ,b.mod_chansub
,b.quota_rep_descr ,b.quota_rep_descr
,b.director_descr ,b.director_descr
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric value_loc ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.value_loc*s.factor END)::numeric value_loc
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price ELSE b.fb_val_loc*s.factor*r_rate END)::numeric value_usd ,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.value_loc*s.factor*r_rate END)::numeric value_usd
,0 cost_loc ,0 cost_loc
,0 cost_usd ,0 cost_usd
,0 units ,0 units