1
SELECT Id, to, Subject, Body, DateCreated, DateSent 
FROM Emails

Gives the following error:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'to'.

Any idea why?

TO is highlighted, so I guess, it is because it thinks that is a keyword, anyway to prevent this?

Cheers.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
bobo2000
  • 1,699
  • 7
  • 29
  • 53
  • Also see: http://stackoverflow.com/questions/2901453/sql-standard-to-escape-column-names – Oded Apr 10 '12 at 12:36

2 Answers2

5

Yes, put to in brackets like this [to]

Eric Petroelje
  • 58,601
  • 9
  • 123
  • 175
0

You escape it by surrounding it with [] (SQL Server specific):

SELECT Id,[to],Subject,Body,DateCreated,DateSent 
FROM Emails

You can also use the standard SQL escape, " as detailed here:

SELECT Id,"to",Subject,Body,DateCreated,DateSent 
FROM Emails
Community
  • 1
  • 1
Oded
  • 477,625
  • 97
  • 867
  • 998