我有一个upadate插入SCD查询,我试图转换为合并到如下:
UPDATE A FROM X.CUSTOMER A,Y.T_CIF_CIS_CUSTOMER B
SET
EFFECTIVE_END_DATE = CAST('2016-05-11' AS DATE FORMAT 'YYYYMMDD'),
DW_UPD_LOAD_TIMESTAMP = Current_timestamp(6)
WHERE
COALESCE(TRIM(B.UNIQUE_ID_IN_SOURCE_SYSTEM),'') = COALESCE(TRIM(A.UNIQUE_ID_IN_SOURCE_SYSTEM),'')
AND A.EFFECTIVE_END_DATE= '2016-05-11'
AND B.EFFECTIVE_END_DATE<> '3499-12-31'
AND A.FILE_ID=B.FILE_ID
AND A.COUNTRY_CODE=B.COUNTRY_CODE
;
INSERT X.CUSTOMER
(col1,col2)
SELECT
col1, col2
FROM Y.T_CIF_CIS_CUSTOMER SRC1
WHERE
EFFECTIVE_START_DATE = '2016-05-11'
AND EFFECTIVE_END_DATE= '3499-12-31'
我正在使用以下合并声明:
merge INTO X.CUSTOMER TGT
using Y.T_CIF_CIS_CUSTOMER SRC on
COALESCE(TRIM(SRC.UNIQUE_ID_IN_SOURCE_SYSTEM),'') = COALESCE(TRIM(TGT.UNIQUE_ID_IN_SOURCE_SYSTEM),'')
AND TGT.EFFECTIVE_END_DATE= '2016-05-11'
AND SRC.EFFECTIVE_END_DATE<> '3499-12-31'
AND TGT.FILE_ID=SRC.FILE_ID
AND SRC.COUNTRY_CODE=SRC.COUNTRY_CODE
when matched then update
SET EFFECTIVE_END_DATE = CAST('2016-05-11' AS DATE FORMAT 'YYYYMMDD'),
DW_UPD_LOAD_TIMESTAMP = Current_timestamp(6)
WHEN NOT MATCHED THEN INSERT values(
SRC.CUSTOMER_ID,
SRC.CUSTOMER_LIFE_CYCLE_TYPE_ID...
)
/*WHERE
EFFECTIVE_START_DATE = '2016-05-11'
AND EFFECTIVE_END_DATE= '3499-12-31'
;
*/
任何人都可以告诉我哪里出错了。是否必须在这里使用PI作为搜索条件?