Friday, March 21, 2008

Getting the list of columns for a table

SELECT TOP 1
STUFF((SELECT ‘, ‘ + T2.COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS AS T2 WHERE T2.TABLE_NAME = T1.TABLE_NAME FOR XML PATH (”)), 1, 2,”) AS COL_NAMES
FROM INFORMATION_SCHEMA.COLUMNS AS T1
WHERE T1.TABLE_NAME = ‘CONCISE_DATA’
ORDER BY T1.ORDINAL_POSITION

Getting the list of columns for a table

No comments: