From 5e4690a1f4d68e05db03695f92a9a0ccd4a4af0d Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Thu, 13 Feb 2020 12:47:01 -0500 Subject: [PATCH] swap out value fields --- route_sql/scale_vupd.sql | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/route_sql/scale_vupd.sql b/route_sql/scale_vupd.sql index 613df99..62991ef 100644 --- a/route_sql/scale_vupd.sql +++ b/route_sql/scale_vupd.sql @@ -205,18 +205,18 @@ FROM ,pscale AS ( SELECT (SELECT pincr::numeric FROM target) incr - ,(SELECT sum(fb_val_loc * r_rate) FROM volume) base - ,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN + ,(SELECT sum(value_loc * r_rate) FROM volume) base + ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN --if the base value is -0- scaling will not work, need to generate price, factor goes to -0- 0 ELSE --if the target $amount is not achieved, adjust further - ((SELECT pincr::numeric FROM target)-(SELECT sum(fb_val_loc * r_rate) FROM volume))/(SELECT sum(fb_val_loc * r_rate) FROM volume) + ((SELECT pincr::numeric FROM target)-(SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(value_loc * r_rate) FROM volume) END factor - ,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN - CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume)) <> 0 THEN + ,CASE WHEN (SELECT sum(value_loc * r_rate) FROM volume) = 0 THEN + CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume)) <> 0 THEN --if the base value is -0- but the target value hasn't been achieved, derive a price to apply - ((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume) + ((SELECT pincr::numeric FROM target) - (SELECT sum(value_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume) ELSE 0 END @@ -291,10 +291,10 @@ FROM ,0 fb_cst_loc ,0 fb_cst_loc_cur ,0 fb_cst_loc_fut - --,b.fb_val_loc*s.factor fb_val_loc - ,(CASE WHEN s.factor = 0 THEN b.units * 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.fb_val_loc_pl*s.factor END)::numeric fb_val_loc_pl - --,b.fb_val_loc_pl*s.factor fb_val_loc_pl + --,b.value_loc*s.factor 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.units * s.mod_price/b.r_rate ELSE b.value_loc_pl*s.factor END)::numeric value_loc_pl + --,b.value_loc_pl*s.factor value_loc_pl ,b.calc_status --0 ,b.flag --0 ,b.orderdate @@ -332,8 +332,8 @@ FROM ,b.mod_chansub ,b.quota_rep_descr ,b.director_descr - ,(CASE WHEN s.factor = 0 THEN b.units * 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 ELSE b.fb_val_loc*s.factor*b.r_rate END)::numeric value_usd + ,(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.units * s.mod_price ELSE b.value_loc*s.factor*b.r_rate END)::numeric value_usd ,0 cost_loc ,0 cost_usd ,0 units