简体   繁体   中英

How do I use SELECT on columns that don't have column names in SQL Server 2008 R2?

Here's my code:

SELECT DISTINCT Column 3
FROM [TestTable].[dbo].data

I get an error on "Column 3". The error is Incorrect syntax near '3'.

My table has no column names so I don't know how to run my Select command on the third column.

If the name of you third column is indeed 'Column 3', you need to run this query:

SELECT DISTINCT [Column 3]
FROM [TestTable].[dbo].data

AFAIK it's impossible to have a table with no column names

Run

USE TestTable
GO

select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='data'

to get the column names

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM