0

Possible Duplicate:
How to deal with SQL column names that look like SQL keywords?

SELECT thing.Column FROM mytable thing

When I run this, SQL Server says that I have "Incorrect syntax near the keyword 'Column'

Community
  • 1
  • 1
MedicineMan
  • 15,008
  • 32
  • 101
  • 146
  • quick fix is to use `[` and `]` around the column name, but the **real solution** is to not use reserved words and change the column name to something else. – RacerX Mar 22 '11 at 13:26

2 Answers2

1

You can enclose the column name in square brackets, thusly:

SELECT thing.[Column] FROM mytable thing

You can also use double-quotes (I believe this is the more standard SQL syntax):

SELECT thing."Column" FROM mytable thing

Note that double-quotes only work when QUOTED_IDENTIFIER is on, however it is on by default.

Here is the MSDN reference on delimited identifiers.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
1

Like this:

SELECT [thing].[Column] FROM [mytable] AS [thing]

Keep trying to use those brackets every time, cause You never know when Your system will migrate to a newer version and if the new one hasn't got new set of reserved words.

Piotr Salaciak
  • 1,653
  • 1
  • 15
  • 28