193 lines
6.9 KiB
MySQL
193 lines
6.9 KiB
MySQL
|
----------------------------SET BILL-TO REP------------------------------------
|
||
|
|
||
|
UPDATE
|
||
|
RLARP.OSMF_DEV S
|
||
|
SET
|
||
|
BILL_REP = C.BVSALM
|
||
|
,BILL_CLASS = C.BVCLAS
|
||
|
,BILL_TERR = C.BVTERR
|
||
|
FROM
|
||
|
LGDAT.CUST C
|
||
|
WHERE
|
||
|
C.BVCUST = S.BILL_CUST
|
||
|
AND (
|
||
|
COALESCE(S.BILL_REP,'') <> C.BVSALM
|
||
|
OR COALESCE(S.BILL_CLASS,'') <> C.BVCLAS
|
||
|
OR COALESCE(S.BILL_TERR,'') <> C.BVTERR
|
||
|
);
|
||
|
|
||
|
----------------------------SET SHIP-TO REP------------------------------------
|
||
|
|
||
|
UPDATE
|
||
|
RLARP.OSMF_DEV S
|
||
|
SET
|
||
|
SHIP_REP = C.BVSALM
|
||
|
,SHIP_CLASS = C.BVCLAS
|
||
|
,SHIP_TERR = C.BVTERR
|
||
|
FROM
|
||
|
LGDAT.CUST C
|
||
|
WHERE
|
||
|
C.BVCUST = S.SHIP_CUST
|
||
|
AND (
|
||
|
COALESCE(S.SHIP_REP,'') <> C.BVSALM
|
||
|
OR COALESCE(S.SHIP_CLASS,'') <> C.BVCLAS
|
||
|
OR COALESCE(S.SHIP_TERR,'') <> C.BVTERR
|
||
|
);
|
||
|
|
||
|
----------------------------SET BILLTO GROUP------------------------------------
|
||
|
|
||
|
UPDATE
|
||
|
RLARP.OSMF_DEV O
|
||
|
SET
|
||
|
ACCOUNT = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
|
||
|
FROM
|
||
|
LGDAT.CUST C
|
||
|
WHERE
|
||
|
C.BVCUST = O.BILL_CUST
|
||
|
AND CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END <> COALESCE(O.ACCOUNT,'');
|
||
|
|
||
|
|
||
|
----------------------------SET SHIPTO GROUP------------------------------------
|
||
|
|
||
|
UPDATE
|
||
|
RLARP.OSMF_DEV O
|
||
|
SET
|
||
|
SHIPGRP = CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END
|
||
|
FROM
|
||
|
LGDAT.CUST C
|
||
|
WHERE
|
||
|
C.BVCUST = O.SHIP_CUST
|
||
|
AND CASE BVADR6 WHEN '' THEN BVNAME ELSE BVADR6 END <> COALESCE(O.SHIPGRP,'');
|
||
|
|
||
|
|
||
|
---------------------------SET CHANNEL-----------------------------------------
|
||
|
|
||
|
|
||
|
UPDATE
|
||
|
rlarp.osmF_dev
|
||
|
SET
|
||
|
CHAN = CASE SUBSTRING(BILL_CLASS,2,3)
|
||
|
--if the bill to class is ditsributor, then it's either warehouse or drop
|
||
|
WHEN 'DIS' THEN
|
||
|
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
||
|
CASE SUBSTRING(SHIP_CLASS,2,3)
|
||
|
WHEN 'DIS' THEN 'WHS'
|
||
|
ELSE 'DRP'
|
||
|
END
|
||
|
--CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END
|
||
|
--everything else does not involve a distributor and is considered direct
|
||
|
ELSE 'DIR'
|
||
|
END,
|
||
|
CHANSUB = CASE SUBSTRING(BILL_CLASS,2,3)
|
||
|
WHEN 'DIS' THEN
|
||
|
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
||
|
CASE SUBSTRING(SHIP_CLASS,2,3)
|
||
|
WHEN 'DIS' THEN 'WHS'
|
||
|
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
|
||
|
END
|
||
|
WHEN 'MAS' THEN 'RMN'
|
||
|
WHEN 'NAT' THEN 'RMN'
|
||
|
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
|
||
|
END
|
||
|
WHERE
|
||
|
COALESCE(CHAN,'') <> CASE SUBSTRING(BILL_CLASS,2,3)
|
||
|
--if the bill to class is ditsributor, then it's either warehouse or drop
|
||
|
WHEN 'DIS' THEN
|
||
|
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
||
|
CASE SUBSTRING(SHIP_CLASS,2,3)
|
||
|
WHEN 'DIS' THEN 'WHS'
|
||
|
ELSE 'DRP'
|
||
|
END
|
||
|
--CASE WHEN RTRIM(SUBSTRING(LTRIM(SC.BVADR7)||SC.BVNAME,1,30)) = RTRIM(SUBSTRING(LTRIM(BC.BVADR7)||BC.BVNAME,1,30)) THEN 'DIS' ELSE 'DRP' END
|
||
|
--everything else does not involve a distributor and is considered direct
|
||
|
ELSE 'DIR'
|
||
|
END
|
||
|
OR
|
||
|
COALESCE(CHANSUB,'') <> CASE SUBSTRING(BILL_CLASS,2,3)
|
||
|
WHEN 'DIS' THEN
|
||
|
--if the ship-to is a different name than the bill-to then it's drop, otherwise it's warehouse
|
||
|
CASE SUBSTRING(SHIP_CLASS,2,3)
|
||
|
WHEN 'DIS' THEN 'WHS'
|
||
|
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDP' ELSE 'DRP' END
|
||
|
END
|
||
|
WHEN 'MAS' THEN 'RMN'
|
||
|
WHEN 'NAT' THEN 'RMN'
|
||
|
ELSE CASE SUBSTRING(SHIP_CLASS,1,1) WHEN 'R' THEN 'RDI' ELSE 'DIR' END
|
||
|
END;
|
||
|
|
||
|
|
||
|
---------------------------SET QUOTA REP---------------------------------------
|
||
|
|
||
|
|
||
|
UPDATE
|
||
|
RLARP.OSMF_DEV S
|
||
|
SET
|
||
|
DSM = CR.QUOTA_REP
|
||
|
FROM
|
||
|
(
|
||
|
SELECT DISTINCT
|
||
|
VERSION,
|
||
|
COALESCE(GLEC,'') GLEC,
|
||
|
COALESCE(MING,'') MING,
|
||
|
BILL_CUST,
|
||
|
SHIP_CUST,
|
||
|
------------quota rep column--------------
|
||
|
RTRIM(
|
||
|
--retail items go to currep, or if null go to 90005
|
||
|
CASE WHEN S.GLEC IN ('1RE','1CU') THEN
|
||
|
CASE WHEN BVCTRY = 'CAN' THEN
|
||
|
--Rachel Bowman
|
||
|
'50300'
|
||
|
ELSE
|
||
|
--select customers go to select reps
|
||
|
CASE ACCOUNT
|
||
|
------Alecia Latini-------------------------------
|
||
|
WHEN 'DO IT BEST' THEN '90006'
|
||
|
WHEN 'ACE HARDWARE' THEN '90006'
|
||
|
WHEN 'ALDI' THEN '90006'
|
||
|
WHEN 'AMAZON.COM' THEN '90006'
|
||
|
WHEN 'GARDEN RIDGE CORP' THEN '90006' --AKA "At Home"
|
||
|
WHEN 'TRUE VALUE' THEN '90006'
|
||
|
WHEN 'WAYFAIR' THEN '90006'
|
||
|
WHEN 'GRIFFIN' THEN '90006'
|
||
|
WHEN 'WAL-MART' THEN '90006'
|
||
|
------Tony Landino--------------------------------
|
||
|
WHEN 'THE HOME DEPOT' THEN '50802'
|
||
|
WHEN 'FRED MEYER' THEN '50802'
|
||
|
WHEN 'MENARDS' THEN '50802'
|
||
|
WHEN 'KROGER' THEN '50802'
|
||
|
WHEN 'OCEAN STATE JOBBERS' THEN '50802'
|
||
|
WHEN 'AURORA WHOLESALE' THEN '50802'
|
||
|
WHEN 'LEON KORRAL' THEN '50802'
|
||
|
--all other retail goes to Doran Marable-----------
|
||
|
ELSE '50200'
|
||
|
END
|
||
|
END
|
||
|
--minor group b52 goes to dedicated rep
|
||
|
ELSE
|
||
|
CASE WHEN MING = 'B52' THEN
|
||
|
'PW'
|
||
|
--gdir, ndir go to bill-to rep
|
||
|
ELSE
|
||
|
CASE WHEN BILL_CLASS IN ('GDIR','NDIR') THEN
|
||
|
BILL_REP
|
||
|
ELSE
|
||
|
SHIP_REP
|
||
|
END
|
||
|
END
|
||
|
END
|
||
|
) QUOTA_REP
|
||
|
FROM
|
||
|
RLARP.OSMF_DEV S
|
||
|
LEFT OUTER JOIN LGDAT.CUST ON
|
||
|
BVCUST = BILL_CUST
|
||
|
WHERE
|
||
|
COALESCE(GLEC,'') IS NOT NULL
|
||
|
) CR
|
||
|
WHERE
|
||
|
CR.VERSION = S.VERSION
|
||
|
AND CR.GLEC = COALESCE(S.GLEC,'')
|
||
|
AND CR.MING = COALESCE(S.MING,'')
|
||
|
AND CR.BILL_CUST = S.BILL_CUST
|
||
|
AND CR.SHIP_CUST = S.SHIP_CUST
|
||
|
AND COALESCE(S.DSM,'') <> CR.QUOTA_REP;
|