Top users - outside of SO (checking reputation on a single site)


Please login or register to vote for this query.

(click on this box to dismiss)

This query shows the top users outside of SO. It checks for reputation on a single site.

Drupal Answers

Q&A for Drupal developers and administrators

-- var to hold the complete query as text
declare @sql nvarchar(max)

-- use the STRING_AGG function to get all SQL
-- projection over the complete result
Select @sql = string_agg(N'Select 
        '''+ convert(nvarchar(max),quotename([Name])) + N''' site
       -- , displayname
       , reputation
       , concat('''',accountid,''?tab=accounts'',''|'',displayname) [network profile]
       , id
From ' + convert(nvarchar(max),quotename([Name])) + N'..Users'
-- this is what gets used to concatenate all those strings
-- the data and grouping over the inner query
+ '
order by reputation desc
From sys.Databases
Where database_id > 5 -- skip the first 5 databases, they have nothing for us
-- let's not include meta sites, except MSE
and (Name not Like '%.Meta' or Name = 'StackExchange.Meta')
and name <> 'stackoverflow'

print @sql -- this gets shown on the Messages tab

exec(@sql) -- this executes the SQL statement that is the @sql variable

Enter Parameters

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