From fb1fcabb00fb7b52f7f72ee6bc7c2564fbe0410a Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 26 Feb 2020 10:35:41 -0500 Subject: [PATCH] coalesce DBA and coalesce FX for local --- route_sql/new_basket.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index 807057b..a2426bd 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -275,8 +275,8 @@ SELECT ,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm ,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr ,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director - ,CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END billto_group - ,CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE bc.BVADR6 END shipto_group + ,COALESCE(CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END,b.bill_cust_descr) billto_group + ,COALESCE(CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE bc.BVADR6 END,b.ship_cust_descr) shipto_group ,CASE SUBSTRING(bc.bvclas,2,3) --if the bill to class is ditsributor, then it's either warehouse or drop WHEN 'DIS' THEN @@ -317,7 +317,7 @@ SELECT ,copr.curr c_currency --master data ,cx.rate c_rate --master data ,b.units - ,b.value_usd / rx.rate --b.value is denominated in USD, need to apply currency to get to local + ,b.value_usd / COALESCE(rx.rate,1) --b.value is denominated in USD, need to apply currency to get to local, assume 1 if using a fake customer ,b.value_usd value_usd --b.value is already denominated in usd ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units cost_loc ,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_usd