Code to get list of all the columns in comma separated format

Posted by Virendradugar under Sql Server category on | Views : 1800
Below given simple sql query will give the column list of the table1 in comma separated format.

DECLARE @ColumnList varchar(max)

SELECT @ ColumnList = COALESCE(@EmployeeList + ', ', '') +
CAST(column_name AS varchar(100))
FROM Information_schema.columns where table_name = 'Table1'

Print @ ColumnList

Note : Replace table1 with your table name.

Comments or Responses

Login to post response