SELECT [t].[name] TableName, STRING_AGG([c].[name], ', ') WITHIN GROUP (ORDER BY [c].[column_id] ASC) [ColList] FROM [db.api-bd-slcr.yarmill.com].[sys].[tables] [t] INNER JOIN [db.api-bd-slcr.yarmill.com].[sys].[schemas] [s] ON [s].[schema_id] = [t].[schema_id] INNER JOIN [db.api-bd-slcr.yarmill.com].[sys].[columns] [c] ON [c].[object_id] = [t].[object_id] WHERE [s].[name] = 'dbo' AND [t].[name] <> '__RefactorLog' GROUP BY [t].[name] GO