declare @sql nvarchar(max) create table #dbs(dbname sysna...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Music Fans Meta

Q&A about the site for music historians, critics, and fans

declare @sql nvarchar(max)
create table #dbs(dbname sysname, userid int)

select @sql = concat(
'insert into #dbs select * from ( ', string_agg(concat(N'select ''', convert(nvarchar(max),name), 
N''' [dbbame] 
, id
from ', convert(nvarchar(max),quotename(name)), N'.dbo.users
where accountid = ''11660265''
')
, N' union all ')
, ' ) data')
from sys.databases
where database_id > 4
and has_dbaccess(name) = 1 

exec(@sql)

select * from #dbs

/*
select top 1 
     id as [Comment Link]
from comments 
where text like '%@d4rk4ng31%'
*/

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results