Storing Column Names of a table in CSV Format


DECLARE @commaSeperatedCols VARCHAR(MAX)
DECLARE @TableName VARCHAR(100)

SET @TableName = 'Your_Table_Name'

SELECT @commaSeperatedCols = COALESCE(@commaSeperatedCols+',' ,'') + COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName

SELECT @commaSeperatedCols

Comments

Popular posts from this blog

SSIS vs. T-SQL

Sync SSAS Cube From One Environment to Another

SQL Function to replace special characters from a string