Total rep from answers: upvotes, downvotes, accepts, bounties (repcap ignored)

2

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- Legendary Badge advancement
-- Retrieve details on the race to legendary for all site users.

DECLARE @UserId INT = ##UserId##

SELECT UserId as [User Link],
       sum(RepChange) as [Rep]
  FROM (
      SELECT
          CASE VoteTypeId
              WHEN 1 THEN 15
              WHEN 2 THEN 10
              WHEN 3 THEN -2
              WHEN 9 THEN BountyAmount
              END RepChange,
      Posts.OwnerUserId UserId
      FROM Votes
          INNER JOIN Posts ON Posts.Id = Votes.PostId
      WHERE VoteTypeId IN (1,2,3,9)
          AND Posts.OwnerUserId = @UserId
          AND Posts.PostTypeId = 2
          AND Posts.CommunityOwnedDate IS NULL
  ) v GROUP BY UserId

Enter Parameters

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