简体   繁体   English

如何在SQL Server 2008 R2中没有列名的列上使用SELECT?

[英]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". 我在“第3列”上收到错误。 The error is Incorrect syntax near '3'. 错误是'3'附近的语法不正确。

My table has no column names so I don't know how to run my Select command on the third column. 我的表没有列名,所以我不知道如何在第三列上运行我的Select命令。

If the name of you third column is indeed 'Column 3', you need to run this query: 如果第三列的名称确实是“列3”,则需要运行此查询:

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

AFAIK it's impossible to have a table with no column names AFAIK不可能有一个没有列名的表

Run

USE TestTable
GO

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

to get the column names 获取列名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定是否安装了本地SQL Server 2008 R2 - How do I to find out if I have a local SQL Server 2008 R2 installed 如何仅使用字符串函数(SQL Server 2008 R2)将定界的字符串解析为列? - How do I parse a delimited string into columns using only string functions (SQL Server 2008 R2)? 如何在 SQL Server 2008 R2 的 T-SQL 中格式化数字? - How do I format a number in T-SQL for SQL Server 2008 R2? 如何在sql server 2008 r2中创建查询 - How do I create query in sql server 2008 r2 如何在SQL Server 2008 R2中使用CONCAT函数? - How do I use the CONCAT function in SQL Server 2008 R2? 如何在实体框架和SQL Server 2008 R2中使用希伯来字符? - How do I use Hebrew characters with Entity Framework and SQL Server 2008 R2? SQL Server 2008 R2不会耗尽特定任务的所有资源 - SQL Server 2008 R2, don't use up all resources for a specific task 如何通过使用一行分割同一列上的另一行对 SQL Server 2008 R2 表的列进行一些计算 - How to do some calculations on columns of a SQL Server 2008 R2 table by using a row divide another row on the same column 如何在MS SQL Server 2008 R2中不使用完全限定的表名 - How to NOT use fully qualified table names in MS SQL Server 2008 R2 如何删除SQL Server 2008 R2中所有行只有一个值的多个列 - How to remove multiple columns that have only one value across all rows in SQL Server 2008 R2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM