0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
confusedMind
  • 2,573
  • 7
  • 33
  • 74

1 Answers1

3

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.

jpw
  • 44,361
  • 6
  • 66
  • 86
  • Oh Thank you , i was doing it like [Target.Form Number ] :). – confusedMind Mar 01 '15 at 04:04
  • @confusedMind Using double-quotes should work too (it's what the ANSI standard uses if memory serves me right, but brackets seem to be the default for T-SQL devs in my experience). – jpw Mar 01 '15 at 04:08