1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| DECLARE @SQL NVARCHAR(max) SET @SQL = stuff(( SELECT ' UNION SELECT ' + quotename(NAME, '''') + ' as Db_Name, Name collate SQL_Latin1_General_CP1_CI_AS as Table_Name FROM ' + quotename(NAME) + '.sys.tables WHERE NAME LIKE ''%'' + @TableName + ''%''' FROM sys.databases ORDER BY NAME FOR XML PATH('') ,type ).value('.', 'nvarchar(max)'), 1, 8, '')
EXECUTE sp_executeSQL @SQL ,N'@TableName varchar(30)' ,@TableName = 'admin'
|