cannot do a normal join, bill to customer may not be in joined table, change to subquery
This commit is contained in:
parent
b9ff9c1493
commit
6984b039f2
@ -32,28 +32,25 @@ SET
|
||||
------------quota rep column--------------
|
||||
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
|
||||
CASE WHEN COALESCE(o.segm,'') = 'Retail' AND COALESCE(cu.currep,'') <> '' THEN
|
||||
cu.currep
|
||||
--default logic
|
||||
ELSE
|
||||
CASE SUBSTR(b.bvclas,2,3)
|
||||
WHEN 'DIS' THEN
|
||||
s.bvsalm
|
||||
ELSE
|
||||
b.bvsalm
|
||||
END
|
||||
CASE WHEN COALESCE(o.segm,'') = 'Retail' AND COALESCE((SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust),'') <> ''
|
||||
THEN
|
||||
(SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust)
|
||||
--default logic
|
||||
ELSE
|
||||
CASE SUBSTR(b.bvclas,2,3)
|
||||
WHEN 'DIS' THEN s.bvsalm
|
||||
ELSE b.bvsalm
|
||||
END
|
||||
END
|
||||
END,
|
||||
billto_group = CASE b.bvadr6 WHEN '' THEN b.bvname ELSE b.bvadr6 END,
|
||||
shipto_group = CASE s.bvadr6 WHEN '' THEN s.bvname ELSE s.bvadr6 END
|
||||
FROM
|
||||
lgdat.cust b,
|
||||
lgdat.cust s,
|
||||
lgpgm.usrcust cu
|
||||
lgdat.cust s
|
||||
WHERE
|
||||
b.bvcust = rtrim(substring(o.bill_cust_descr,1,8))
|
||||
AND s.bvcust = rtrim(substring(o.ship_cust_descr,1,8))
|
||||
AND cu.cucust = b.bvcust;
|
||||
AND s.bvcust = rtrim(substring(o.ship_cust_descr,1,8));
|
||||
--BEGIN;
|
||||
|
||||
UPDATE
|
||||
|
Loading…
Reference in New Issue
Block a user