If I understand the question correctly, you want the list into a single column in a single row. If that is the case, consider the following:
WITH ColumnnList (List) AS (
SELECT ';' + c.Column_Name
FROM INFORMATION_SCHEMA.Columns c
WHERE c.Table_Name = 'SOURCETABLENAME'
FOR XML PATH ('')
)
INSERT INTO TARGETTABLENAME (TARGETCOLUMNNAME)
SELECT SUBSTRING(a.List, 2, 99999)
FROM ColumnnList a
Just remember to change:
- SOURCETABLENAME to the name of the table for which to list the columns
- TARGETTABLENAME to the name of the table where you want to insert the data
- TARGETCOLUMNNAME to the name of the target column in the target table
- optionally change the separator to what you wish. I've used semicolon (
;
)