Tag-badge SCORE


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- Calculates the net score for a tag badge

DECLARE @UserId int = ##UserId##;
DECLARE @TagName nvarchar(35) = ##Tag:string##;

SELECT SUM(IIF(Votes.VoteTypeId = 2, 1, -1))
  SELECT Answers.ID AS AnswerID
  FROM Posts Questions
  INNER JOIN PostTags ON PostTags.PostId = Questions.Id
  INNER JOIN Tags ON PostTags.TagId = Tags.Id
  INNER JOIN Posts Answers ON Answers.ParentId = Questions.Id
    Questions.PostTypeId = 1 AND
    Questions.CommunityOwnedDate IS NULL AND
    Questions.DeletionDate IS NULL AND
    (Questions.OwnerUserId IS NULL OR Questions.OwnerUserId <> @UserId) AND
    Tags.TagName = @TagName AND
    Answers.PostTypeId = 2 AND
    Answers.DeletionDate IS NULL AND
    Answers.OwnerUserId = @UserId
) AS MyAnswers
INNER JOIN Votes ON Votes.PostId = MyAnswers.AnswerID
WHERE Votes.VoteTypeId = 2 OR Votes.VoteTypeId = 3

Enter Parameters

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