开发者

how do I query a column that has a name similar to a reserved word? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to deal with SQL column names that look like SQL keywo开发者_如何学Gords?

SELECT thing.Column FROM mytable thing

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜