1)
CREATE TABLE DB1.TEST_ITEM_PRICE AS (SELECT * FROM DB.ITEM_PRICE) WITH DATA;
2)
INSERT DB1.TEST_ITEM_PRICE SELECT * FROM DB.ITEM_PRICE;
3)
UPDATE DB1.TEST_ITEM_PRICE
FROM
(
SELECT sip.item_id
,MIN(CAST(sip.item_price_start_dt AS DATE)) AS item_price_start_dt
FROM DB1.TEST_ITEM_PRICE ip
INNER JOIN
DB.STG_ITEM_PRICE sip
ON ip.item_id = sip.item_id
AND ip.level_cd = sip.level_cd
WHERE UPPER(sip.level_cd) = 'CHAIN'
AND UPPER(sip.item_price_type_cd) = 'PERMANENTPRICE'
HAVING COUNT(*) = 1
GROUP BY sip.item_id
) AS UPD_TBL
SET item_price_end_dt = UPD_TBL.item_price_start_dt-1
WHERE DB1.TEST_ITEM_PRICE.item_id = UPD_TBL.item_id
0 comments:
Post a Comment