Hari
Hari

Reputation: 127

MS SQL server 2005 - Error while querying with a column name as key

I have a table with a column name as "key". I am unable to filter based on that column

select * from myTable where key='someVal'

I get the following error

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

I cannot change the column name. How I can circumvent this issue?

Upvotes: 0

Views: 27

Answers (1)

Ron Smith
Ron Smith

Reputation: 3266

It's because key is a keyword. If you have keywords as object names, you need to put them in brackets:

select * from myTable where [key]='someVal'

Upvotes: 1

Related Questions