INSERT INTO CONTACT_XREF 
SELECT r.CONTENT_ID, r.USN AS XREF_KEY, 
CURRENT_TIMESTAMP AS START_DATE, CURRENT_TIMESTAMP AS LAST_UPDATE_DATE, CURRENT_TIMESTAMP AS ENTRY_DATE, NULL AS END_DATE, 
'ALARM' AS SOURCE, r.CONTENT_ID AS CROSS_REFERENCE, 'PASS-' || r.PASSWD ||' |PROMPT-' || r.PROMPT || ' |CODE-' || r.CODE AS DATA, 1 AS XORDER
FROM CONTACT r
WHERE r.PASSWD <> ''

UNION ALL

SELECT r.CONTENT_ID, r.USN AS XREF_KEY, 
CURRENT_TIMESTAMP AS START_DATE, CURRENT_TIMESTAMP AS LAST_UPDATE_DATE, CURRENT_TIMESTAMP AS ENTRY_DATE, NULL AS END_DATE, 
'#A' AS SOURCE, r.CONTENT_ID AS CROSS_REFERENCE, r.MAINTAIN AS DATA, 1 AS XORDER
FROM CONTACT r
WHERE r.MAINTAIN <> ''

UNION ALL

SELECT r.CONTENT_ID, r.USN AS XREF_KEY, 
CURRENT_TIMESTAMP AS START_DATE, CURRENT_TIMESTAMP AS LAST_UPDATE_DATE, CURRENT_TIMESTAMP AS ENTRY_DATE, NULL AS END_DATE, 
'#K' AS SOURCE, r.CONTENT_ID AS CROSS_REFERENCE, r.KEY1 || 'Phone-' || r.TEL1 AS DATA, 1 AS XORDER
FROM CONTACT r
WHERE r.KEY1 <> ''

UNION ALL

SELECT r.CONTENT_ID, r.USN AS XREF_KEY, 
CURRENT_TIMESTAMP AS START_DATE, CURRENT_TIMESTAMP AS LAST_UPDATE_DATE, CURRENT_TIMESTAMP AS ENTRY_DATE, NULL AS END_DATE, 
'#K' AS SOURCE, r.CONTENT_ID AS CROSS_REFERENCE, r.KEY2 || 'Phone-' || r.TEL2 AS DATA, 2 AS XORDER
FROM CONTACT r
WHERE r.KEY2 <> ''

UNION ALL

SELECT r.CONTENT_ID, r.USN AS XREF_KEY, 
CURRENT_TIMESTAMP AS START_DATE, CURRENT_TIMESTAMP AS LAST_UPDATE_DATE, CURRENT_TIMESTAMP AS ENTRY_DATE, NULL AS END_DATE, 
'#K' AS SOURCE, r.CONTENT_ID AS CROSS_REFERENCE, r.KEY3 || 'Phone-' || r.TEL3 AS DATA, 3 AS XORDER
FROM CONTACT r
WHERE r.KEY3 <> ''

UNION ALL

SELECT r.CONTENT_ID, r.USN AS XREF_KEY, 
CURRENT_TIMESTAMP AS START_DATE, CURRENT_TIMESTAMP AS LAST_UPDATE_DATE, CURRENT_TIMESTAMP AS ENTRY_DATE, NULL AS END_DATE, 
'CON' AS SOURCE, r.CONTENT_ID AS CROSS_REFERENCE, r.CONTACT1 AS DATA, 1 AS XORDER
FROM CONTACT r
WHERE r.CONTACT1 <> ''

UNION ALL

SELECT r.CONTENT_ID, r.USN AS XREF_KEY, 
CURRENT_TIMESTAMP AS START_DATE, CURRENT_TIMESTAMP AS LAST_UPDATE_DATE, CURRENT_TIMESTAMP AS ENTRY_DATE, NULL AS END_DATE, 
'CON' AS SOURCE, r.CONTENT_ID AS CROSS_REFERENCE, r.CONTACT2 AS DATA, 2 AS XORDER
FROM CONTACT r
WHERE r.CONTACT2 <> ''

UNION ALL

SELECT r.CONTENT_ID, r.USN AS XREF_KEY, 
CURRENT_TIMESTAMP AS START_DATE, CURRENT_TIMESTAMP AS LAST_UPDATE_DATE, CURRENT_TIMESTAMP AS ENTRY_DATE, NULL AS END_DATE, 
'CON' AS SOURCE, r.CONTENT_ID AS CROSS_REFERENCE, r.CONTACT3 AS DATA, 3 AS XORDER
FROM CONTACT r
WHERE r.CONTACT3 <> ''
