Wednesday, September 30, 2020

Comma Separated List of all columns for tablename in the Database

 select t.name, 

        STUFF ((

            select ',' + c.name

            from sys.columns c

                join sys.tables tt on tt.object_id = t.object_id and t.object_id = c.object_id

                join sys.schemas s on tt.schema_id = s.schema_id

            order by t.name, c.column_id

            for xml path('')), 1, 1, '') as columns

from sys.tables t

            where t.name = 'Test'--'PutTableNameHere if you want to filter'

No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...