1 | initial version |
There are multiple ways to retrieve column names from a select query in SQL Server:
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'table_name'
Replace 'table_name' with the name of the table you want to retrieve the column names from.
SELECT name
FROM sys.columns
WHERE object_id = OBJECT_ID('table_name')
Replace 'table_name' with the name of the table you want to retrieve the column names from.
EXEC sp_columns 'table_name'
Replace 'table_name' with the name of the table you want to retrieve the column names from.