Analyzing your query in SQL Management Studio gives me the following error:
Msg 10739, Level 15, State 1, Line 7 The list of insert columns used in the MERGE statement cannot contain multipart identifiers. Use single part identifiers.
Then I delete the identifiers ...
MERGE PopulationData AS a USING ImagesData AS b ON a.ID = b.ID WHEN MATCHED THEN UPDATE SET a.SURNAME = 'joe123' WHEN NOT MATCHED THEN INSERT(ID,SURNAME) VALUES (12454,'joe123');
... and the request parses successfully. Thus, the syntax error hardly comes from your MERGE statement. Are you really only executing the expression you posted, or is it part of a larger script or procedure? And if you double-click the error message, it should highlight the line where the syntax error is (at least since SQL 2008).
Update: I noticed that you noted a question for SQL 2005 and 2008, but MERGE is only supported in SQL 2008. Parsing a query in SQL 2005 gives a syntax error.
source share