SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTable' AND ORDINAL_POSITION = '3'
Denne sætning returnerer den tredje kolonne i din tabel
Du skal skrive en transaktions-SQL-sætning som
DECLARE @columnname nvarchar(100), @sql nvarchar(500)
SELECT @columnname = ORDINAL_POSITION FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTable' AND ORDINAL_POSITION = '3'
SET @sql = 'SELECT ' + @columnname + ' FROM mytable'
EXEC @sql