We are having challenges with a Merge statement. The SQL we are using for the source data works fine when run as a select statement, but for some reason will not run when within the merge statement - the error message is :
MERGE Failed. 3707: Syntax error, expected something like a name or a Unicode delimited identifier or a 'ROWID' keyword between ',' and the 'WHEN' keyword.
Output directed to Answer window
Below is the sql - are we missing something?
MERGE INTO BIDW_TABLES.Fact_eL_CertAssignment as tgt
USING
(
SELECT
cast(substr(c.certid,6,character_length(c.certid)) as integer) as S_Cert_ID,
cast(c.PercentageComplete as float) as S_PercentComplete,
cast(c.studentid as integer) as S_Person_ID
from
ODS_TABLES.elearningCertCurAssignment C
where c.studentid = '985710'
) as src
ON
tgt.Person_ID = src.S_Person_ID and tgt.Cert_ID = src.S_Cert_ID
WHEN MATCHED THEN
UPDATE SET
tgt.PercentComplete = src.S_PercentComplete,
WHEN NOT
MATCHED THEN
INSERT
( Cert_ID,
PercentComplete,
Person_ID
)
VALUES
(src.S_Cert_ID,
src.S_PercentComplete,
src.S_Person_ID
)
);