I am trying to execute below query. When I execute subquery alone (derived table B) , I am getting values. But if i use the same in MERGE, it is just updating zeroes.
MERGE INTO DDEWD03S.T1_PRE_TMP TMP
USING
(
SEL WH_CUST_NO , A_MX_CNT
FROM
(SELECT WH_CUST_NO, A_M1_CNT AS A_MX_CNT FROM DDEWD03S.T1_BASE_TMP WHERE A_M1_CNT IS NOT NULL
UNION ALL
SELECT WH_CUST_NO, A_M2_CNT AS A_MX_CNT FROM DDEWD03S.T1_BASE_TMP WHERE A_M2_CNT IS NOT NULL
UNION ALL
SELECT WH_CUST_NO, A_M3_CNT AS A_MX_CNT FROM DDEWD03S.T1_BASE_TMP WHERE A_M3_CNT IS NOT NULL
UNION ALL
SELECT WH_CUST_NO, A_M4_CNT AS A_MX_CNT FROM DDEWD03S.T1_BASE_TMP WHERE A_M4_CNT IS NOT NULL
UNION ALL
SELECT WH_CUST_NO, A_M5_CNT AS A_MX_CNT FROM DDEWD03S.T1_BASE_TMP WHERE A_M5_CNT IS NOT NULL
UNION ALL
SELECT WH_CUST_NO, A_M6_CNT AS A_MX_CNT FROM DDEWD03S.T1_BASE_TMP WHERE A_M6_CNT IS NOT NULL)A
)B
ON TMP.WH_CUST_NO = B.WH_CUST_NO
WHEN MATCHED THEN UPDATE
SET A_MX_CNT = B.A_MX_CNT
My source and target has same WH_CUST_NO AND it is primary index in both. Can any assist.
Aucun commentaire:
Enregistrer un commentaire