How to select a column in SQL Server with a special character in the column name?
29,506
You may want to wrap your column name in square brackets to have your identifier delimited:
SELECT [%Phone] FROM Table1
If the QUOTED_IDENTIFIER
option is set to ON, you can also use ANSI-SQL compliant double quotation marks to delimit identifiers:
SELECT "%Phone" FROM Table1
Author by
Jin Yong
Updated on September 22, 2020Comments
-
Jin Yong over 3 years
I have a table contain the '%' in the column title, and this cause problem when I do the select statement on that column (Find below for more details). Does anyone know how can I select that column by not keeping the original column title?
Example:
Table1 name ref_no tot_sales %Phone ------------------------------- Alan 1 1 100% amy 2 1 50% ken 3 4 30%
Script:
Select %Phone From Table1
Error Message :
Incorrect syntax near phone
-
OMG Ponies over 13 years...and communicate to others never to use unusual characters for table or column names.