-- MOPDB
INSERT INTO CT_MRDS.A_TASK_HISTORY_TARGET (
	A_TASK_HISTORY_TARGET_KEY,
	A_TASK_HISTORY_KEY,
	TARGET_NAME,
	ROW_COUNT_APPLIED,
	ROW_COUNT_REJECTED,
	LOAD_SUCCESSFUL,
	SERVICE_NAME
)
SELECT 
    A_LOAD_HISTORY_TARGET_KEY as A_TASK_HISTORY_TARGET_KEY,
    A_LOAD_SUBPROCESS_FK as A_TASK_HISTORY_KEY,
    TARGET_TABLE_NAME as TARGET_NAME,
    ROW_COUNT_APPLIED as ROW_COUNT_APPLIED,
    ROW_COUNT_REJECTED as ROW_COUNT_REJECTED,
    LOAD_SUCCESSFUL as LOAD_SUCCESSFUL,
    'MOPDB' AS SERVICE_NAME 
FROM
    CT_MOPDB.A_LOAD_HISTORY_TARGET
WHERE
    TARGET_TABLE_NAME IN (
      'CSDB_DEBT',
      'CSDB_DEBT_DAILY',   
      'CSDB_INSTR_DESC_FULL',
      'CSDB_ISSUER_DESC_FULL'
    );


-- ODS
INSERT INTO CT_MRDS.A_TASK_HISTORY_TARGET (
	A_TASK_HISTORY_TARGET_KEY,
	A_TASK_HISTORY_KEY,
	TARGET_NAME,
	ROW_COUNT_APPLIED,
	ROW_COUNT_REJECTED,
	LOAD_SUCCESSFUL,
	SERVICE_NAME
)
SELECT 
    A_LOAD_HISTORY_TARGET_KEY as A_TASK_HISTORY_TARGET_KEY,
    A_ETL_LOAD_SET_FK as A_TASK_HISTORY_KEY,
    TARGET_TABLE_NAME AS TARGET_NAME,
    ROW_COUNT_APPLIED as ROW_COUNT_APPLIED,
    ROW_COUNT_REJECTED as ROW_COUNT_REJECTED,
    'Y' as LOAD_SUCCESSFUL,
    'ODS' AS SERVICE_NAME 
FROM
    CT_ODS.A_LOAD_HISTORY_TARGET 
WHERE
    TARGET_TABLE_NAME IN (
      'OU_CSDB_DEBT', 
      'OU_CSDB_DEBT_DAILY',
      'OU_CSDB_INSTR_DESC_FULL',
      'OU_CSDB_ISSUER_DESC_FULL'
    );
    

COMMIT;	

