Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An issue with specifying a column "Percent" in SQL Select query

Tags:

sql

sql-server

There is a table with a column name PERCENT. I need to run an ordinary SELECT query:

SELECT * 
FROM <my_table>
WHERE PERCENT = 100

However, I get this error message:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'PERCENT'

Is there a way to indicate a column so the system accepts it as a column name instead of a function?

like image 412
Lina Senchenko Avatar asked Dec 14 '22 13:12

Lina Senchenko


1 Answers

PERCENT is a reserved word. Use escape characters:

SELECT *
FROM <my_table>
WHERE [PERCENT] = 100

It is used, for instance, with TOP as in TOP 100 PERCENT.

like image 158
Gordon Linoff Avatar answered Dec 18 '22 00:12

Gordon Linoff