Find users with highest rep on multiple sites


Please login or register to vote for this query.

(click on this box to dismiss)


Q&A for those who study, teach, research and apply economics and econometrics

select dbid, name
into #dbs
from master..sysdatabases
where name not in ('Data.StackExchange', 'master', 'model', 'msdb', 'tempdb')

create table #topusers (
  acountid int,
  userid int,
  rep int,
  site varchar(40)

declare @id int, @db varchar(40), @sql varchar(max)

while (select count(*) from #dbs) > 0
  select top 1 @id = dbid, @db = name from #dbs
  set @sql = '
    insert into #topusers
    select AccountId, Id, Reputation, ''' + @db + '''
    from [' + @db + ']..[Users]
    where Reputation > 10000'
  print @sql
  --exec (@sql)
  delete from #dbs where dbid = @id

select * from #topusers

Enter Parameters

Switch to meta site
loading Hold tight while we fetch your results