1

Hi I have a table which contains filed name as OBJECT.
I am trying to fetch records from the table using select query as follows:

SELECT * 
  FROM table1 
 WHERE OBJECT = "11";

I am getting the following error - INVALID COLUMN NAME.
Looks like its reading OBJECT as SQL KEYWORD and not as table field name.

I am writing this query in sql server management studio.

3 Answers 3

2

Enclose keywords in brackets:

SELECT * FROM table1 WHERE [OBJECT] = '11'
Sign up to request clarification or add additional context in comments.

2 Comments

But don't enclose values in double quotes, use single quotes.
You're right @Johan. I was just copied his original query without double-checking. I edited my answer to use single quotes.
0

Try

select * from table1 where [OBJECT] = '11';

MSDN: Delimited Identifiers

Btw, here is another SO-question to this issue.

Comments

0

Use single quotation marks. But if object is numeric, don't use any quotation marks around the number 11.

             where mycol = 'x'  

             not 

           where mycol = "x"

1 Comment

Thanks.. I realized the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.