diff --git a/route_sql/scale_vupd.sql b/route_sql/scale_vupd.sql index 59ade9d..0042a2c 100644 --- a/route_sql/scale_vupd.sql +++ b/route_sql/scale_vupd.sql @@ -358,9 +358,11 @@ target AS (select target_vol vincr, target_prc pincr) (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 + --if the base value is -0- scaling will not work, need to generate price, factor goes to -0- 0 ELSE - (SELECT pincr::numeric FROM target)/(SELECT sum(fb_val_loc * r_rate) FROM volume) + --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) 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