SQL Server Merge Statement - Incorrect Syntax

sql, sql-server

Solution

The keyword is WHEN, not WHERE :)

More about it here, but a bit much to put into an answer.

Problem

I'm getting the following error when executing this SQL script: ``` MERGE TridionCentres TridionCentres USING (SELECT * FROM #CentresToUpdate) NewInfo ON (TridionCentres.[publication id] = NewInfo.[publication id] AND TridionCentres.centre_number = NewInfo.centre_number) WHERE matched THEN UPDATE SET TridionCentres.centre = NewInfo.centre, TridionCentres.[date] = NewInfo.[date]; ``` Error: Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'WHERE'. I can't see where I've gone wrong!

Original source