Sunday, May 03, 2009

 

SQL Server: Get Comma Separated List of Table Column Names

Nothing earth shatteringly new; just for my reference:

-- Get a comma separated list of a table's column names
SELECT STUFF(
(SELECT
',' + COLUMN_NAME AS [text()]
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'TableName'
Order By Ordinal_position
FOR XML PATH('')
), 1,1, '')


    

Powered by Blogger