Top Reopen Voters


Please login or register to vote for this query.

(click on this box to dismiss)

Programming Puzzles and Code Golf

Q&A for programming puzzle enthusiasts and code golfers

-- Copy of the Top Close Voters query, with PostHistoryTypeId = 11 for Reopen

-- Returns all close voters ordered from most to least votes
-- Only counts closed votes that actually resulted in an open,
-- and does not count deleted questions

-- I wouldn't recommend running this on StackOverflow due to its size

declare @userid int
declare @users table
  userid int,
  ReopenCount int

-- Cursor for all users who can vote to close
declare cur cursor for 
    select id 
    from users
    where reputation >= 500
open cur
fetch next from cur into @userid
while @@fetch_status = 0

  insert into @users(userid, ReopenCount)
  SELECT @userid, count(*)
  FROM PostHistory 
  WHERE PostHistoryTypeId = 11 
  AND Text LIKE '%' + CAST(@userid AS nvarchar) + '%'
  fetch next from cur into @userid

close cur
deallocate cur

-- Return results
select top 50 u.ReopenCount, users.displayname as 'User', 
convert(nvarchar, (select max(creationdate) from posts where ownerUserId =, 101) as [LastPostDate],
convert(nvarchar, (select max(creationdate) from votes where userId =, 101) as [LastVoteDate]
from @users as u
left outer join users on u.userid =
order by u.ReopenCount desc

Enter Parameters

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