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--------------
|
------------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
|
||||||
--default logic
|
(SELECT currep FROM lgpgm.usrcust where cucust = b.bvcust)
|
||||||
ELSE
|
--default logic
|
||||||
CASE SUBSTR(b.bvclas,2,3)
|
ELSE
|
||||||
WHEN 'DIS' THEN
|
CASE SUBSTR(b.bvclas,2,3)
|
||||||
s.bvsalm
|
WHEN 'DIS' THEN s.bvsalm
|
||||||
ELSE
|
ELSE b.bvsalm
|
||||||
b.bvsalm
|
END
|
||||||
END
|
|
||||||
END
|
END
|
||||||
END,
|
END,
|
||||||
billto_group = CASE b.bvadr6 WHEN '' THEN b.bvname ELSE b.bvadr6 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
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user