From f7f26b28049dd2666833be569c7775b374a81e56 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 7 Apr 2021 20:23:12 +0000 Subject: [PATCH] finish work on customer swap, start testing this --- route_sql/swap_cust.sql | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/route_sql/swap_cust.sql b/route_sql/swap_cust.sql index 8e1691a..69b6c16 100644 --- a/route_sql/swap_cust.sql +++ b/route_sql/swap_cust.sql @@ -112,9 +112,9 @@ target AS (SELECT $$swap_doc$$::jsonb swap) FROM rlarp.osm_pool o CROSS JOIN log - INNER JOIN swap ON - swap.bill_to = SUBSTRING(o.bill_cust_descr,1,8) - swap.bill_to = SUBSTRING(o.ship_cust_descr,1,8) + INNER JOIN cust c ON + c.billto = SUBSTRING(o.bill_cust_descr,1,8) + AND c.shipto = SUBSTRING(o.ship_cust_descr,1,8) WHERE -----------------scenario---------------------------- where_clause @@ -125,13 +125,13 @@ target AS (SELECT $$swap_doc$$::jsonb swap) ,o.dplt plnt ---master data ,o.promo --history date mix ,terms - ,bill_cust_descr --history cust mix - ,ship_cust_descr --history cust mix + ,COALESCE(c.bill_r||' - '||c.bill_dba,bill_cust_descr) bill_cust_descr + ,COALESCE(c.ship_r||' - '||c.ship_dba,ship_cust_descr) ship_cust_descr ,dsm ,quota_rep_descr --master data ,director - ,billto_group --master data - ,shipto_group + ,COALESCE(c.bill_dba,billto_group) billto_group + ,COALESCE(c.ship_dba,shipto_group) shipto_group ,chan --master data ,chansub ,chan_retail @@ -174,12 +174,11 @@ target AS (SELECT $$swap_doc$$::jsonb swap) ,o.module FROM remove o - LEFT OUTER JOIN bill ON - bill.billto = rtrim(substring(o.bill_cust_desrc,1,8)) - LEFT OUTER JOIN ship ON - ship.shipto = rtrim(substring(o.ship_cust_desrc,1,8)) - + INNER JOIN cust c ON + c.billto = SUBSTRING(o.bill_cust_descr,1,8) + AND c.shipto = SUBSTRING(o.ship_cust_descr,1,8) ) +--select bill_cust_descr, ship_cust_descr, sum(value_usd) from (SELECT * FROM remove UNION ALL SELECT * FROM repl) x group by bill_cust_descr, ship_cust_descr ,ins AS ( INSERT INTO rlarp.osm_pool SELECT * FROM remove UNION ALL SELECT * FROM repl RETURNING * )