Just put the table name in the @TableName variable.
You can also apply filtering in the where clause to only get certian fields.
Just put the table name in the @TableName variable.
You can also apply filtering in the where clause to only get certian fields.
DECLARE @TableName SYSNAME = 'tablename' SELECT REPLACE(REVERSE(STUFF(REVERSE((SELECT name + ',' AS [data()] FROM sys.columns WHERE OBJECT_NAME(object_id) = @TableName ORDER BY column_id FOR XML PATH(''))),1,1,'')),' ','')