confusedMind
confusedMind

Reputation: 2653

SQL Server 2008 R2 : Merge Query

I am using the following syntax for a merge :

MERGE INTO studentinfo as Target
USING StudentInfo_Temp as Source ON Target.Form Number = Source.Form Number

WHEN MATCHED THEN
   UPDATE 
      SET Target.Form Number = Source.Form Number

WHEN NOT MATCHED THEN
   INSERT ([Form Number], [Academic Program]) 
   VALUES (Source.Form Number, Source.Academic Program);

But I am getting an error above on the line

on Target.Form Number = Source.Form Number

If I replace this by Taget.ID = Source.ID it works fine so I am assuming I have to write a column with a space in name some other way.

Any suggestion on the correct syntax?

Upvotes: 0

Views: 24

Answers (1)

jpw
jpw

Reputation: 44931

Use brackets to enclose the values with spaces:

Target.[Form Number] = Source.[Form Number]

see the section for Delimited identifiers in the documentation for more information.

Upvotes: 3

Related Questions