在SQL Server无法直接实现,参考:
建议在代码中实现
Select name from syscolumns Where ID=OBJECT_ID('表名')
USE TEMPDB
GO
IF OBJECT_ID('TB') IS NOT NULL DROP TABLE TB
GO
CREATE TABLE TB(
COL1 INT
,COL2 INT
,COL3 INT
,COL4 INT
)
GO
DECLARE @SQL VARCHAR(MAX)
SELECT @SQL='SELECT '+NAME+' FROM TB'
FROM SYS.COLUMNS
WHERE OBJECT_ID=OBJECT_ID('TB')
AND COLUMN_ID=3
EXEC (@SQL)