如何查询名称中带有括号()的SQL列? [英] How to query SQL columns that have parentheses ( ) in their name?

查看:1303
本文介绍了如何查询名称中带有括号()的SQL列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

列名看起来像:"Ab.(Cd)"

The column names looks something like: "Ab. (Cd)"

它带有'.'.以及列名中的().

It has , '.' as well as ( ) in the column name.

我尝试在列名周围使用方括号[],也尝试了''和",但没有太大的成功.请帮忙.

I have tried square brackets [ ] around the column name and have also tried ' ' and " " without much success. Please help.

我正在使用SQL Server导入和导出向导来导入一些数据.查询如下:

I am using SQL Server Import and Export Wizard to import some data. The query looks like:

Select 'Trans. Z4 (St 85)' from `'Monthly Prices$'`

使用的完整SQL语句是:

The full SQL statement used is:

以下是查询:Select F1, HH, AECO, Sumas, Stanfield, Malin, [PG&E], Opal, SoCal, SJ, wTX, sTX, HSC, FGTZ3, [Trans. Z4 (St 85)], Dom, [Tetco M3], 'Trans. Z6 (NY)', AGT, Dawn, C Midcon from 'Monthly Prices$'

请注意,表每月价格$"是我要导入的Excel工作簿中的工作表.

Please note that the table 'Monthly Prices$' is a sheet in an Excel workbook that I am trying to import.

推荐答案

您的查询:

Select 'Trans. Z4 (St 85)' from 'Monthly Prices$'

您不能从字符串中SELECT.您需要在表格名称周围使用方括号:

You cannot SELECT from a string. You need to use square brackets around the table name:

Select 'Trans. Z4 (St 85)' from [Monthly Prices$]

但这只是问题的一半.如果运行此命令,则每行将获得相同的字符串"Trans.Z4(St 85)".您还需要在该列名称中使用方括号:

But that's only half of the problem. If you run this, you will get the same string, "Trans. Z4 (St 85)" on every row. You need to use square brackets for that column name as well:

Select [Trans. Z4 (St 85)] from [Monthly Prices$]

这篇关于如何查询名称中带有括号()的SQL列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆