How do I query SQL columns with parentheses () in their name?

Column names look something like "Ab. (Cd)"

He has, '.' and also () in the column name.

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

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

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

      

Full SQL statement used:

Here's the request: 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, Chi, Midcon from 'Monthly Prices$'

Note that the Monthly Prices $ table is a worksheet in an Excel workbook that I am trying to import.

+3


source to share


2 answers


Your request:

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

      

You can't SELECT

out of line. You need to use square brackets around the table name:



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

      

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

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

      

+2


source


I think this is your problem. Often, the wizards will not have as strong an understanding of SQL as writing a statement in SSMS. I was able to create a table with column names but was only able to import it using the wizard if I imported the entire table without using the sql statement. Is this possible for you? I could query the table using parentheses correctly in SSM after these names.



+1


source







All Articles