如何在 SQL Server 中选择列名中带有特殊字符的列? [英] How to select a column in SQL Server with a special character in the column name?
本文介绍了如何在 SQL Server 中选择列名中带有特殊字符的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表在列标题中包含%",当我对该列执行 select 语句时,这会导致问题(在下面查找更多详细信息).有谁知道如何通过不保留原始列标题来选择该列?
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?
示例:
Table1
name ref_no tot_sales %Phone
-------------------------------
Alan 1 1 100%
amy 2 1 50%
ken 3 4 30%
脚本:
Select %Phone From Table1
错误信息:
手机附近的语法错误
推荐答案
您可能希望将列名括在方括号中,以便 标识符分隔:
You may want to wrap your column name in square brackets to have your identifier delimited:
SELECT [%Phone] FROM Table1
如果 QUOTED_IDENTIFIER
选项设置为 ON,您还可以使用符合 ANSI-SQL 的双引号来分隔标识符:
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
这篇关于如何在 SQL Server 中选择列名中带有特殊字符的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文