Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Merge Statement - Incorrect Syntax

Tags:

sql

sql-server

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!

like image 346
NiceYellowEgg Avatar asked Nov 30 '25 02:11

NiceYellowEgg


1 Answers

The keyword is WHEN, not WHERE :)

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

like image 103
fnurglewitz Avatar answered Dec 02 '25 17:12

fnurglewitz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!