SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTable' AND ORDINAL_POSITION = '3'
Pernyataan ini mengembalikan kolom ketiga dari tabel Anda
Anda perlu menulis pernyataan SQL transaksi seperti
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