cannot do a normal join, bill to customer may not be in joined table, change to subquery

This commit is contained in:
Paul Trowbridge 2021-03-08 17:59:20 -05:00
parent b9ff9c1493
commit 6984b039f2

View File

@ -32,15 +32,14 @@ SET
------------quota rep column-------------- ------------quota rep column--------------
CASE WHEN COALESCE(substring(ming_descr,1,3),'') = 'B52' THEN 'PW' ELSE CASE WHEN COALESCE(substring(ming_descr,1,3),'') = 'B52' THEN 'PW' ELSE
--if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available --if the gl expense code is 1RE use the retail rep assigned to the bill-to customer if available
CASE WHEN COALESCE(o.segm,'') = 'Retail' AND COALESCE(cu.currep,'') <> '' THEN CASE WHEN COALESCE(o.segm,'') = 'Retail' AND COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust),'') <> ''
cu.currep THEN
(SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust)
--default logic --default logic
ELSE ELSE
CASE SUBSTR(b.bvclas,2,3) CASE SUBSTR(b.bvclas,2,3)
WHEN 'DIS' THEN WHEN 'DIS' THEN s.bvsalm
s.bvsalm ELSE b.bvsalm
ELSE
b.bvsalm
END END
END END
END, END,
@ -48,12 +47,10 @@ SET
shipto_group = CASE s.bvadr6 WHEN '' THEN s.bvname ELSE s.bvadr6 END shipto_group = CASE s.bvadr6 WHEN '' THEN s.bvname ELSE s.bvadr6 END
FROM FROM
lgdat.cust b, lgdat.cust b,
lgdat.cust s, lgdat.cust s
lgpgm.usrcust cu
WHERE WHERE
b.bvcust = rtrim(substring(o.bill_cust_descr,1,8)) b.bvcust = rtrim(substring(o.bill_cust_descr,1,8))
AND s.bvcust = rtrim(substring(o.ship_cust_descr,1,8)) AND s.bvcust = rtrim(substring(o.ship_cust_descr,1,8));
AND cu.cucust = b.bvcust;
--BEGIN; --BEGIN;
UPDATE UPDATE