Tag-badge SCORE

0

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))
FROM 
(
  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
  WHERE 
    Questions.PostTypeId = 1 AND
    Questions.CommunityOwnedDate IS NULL AND
    Tags.TagName = @TagName AND
    Answers.PostTypeId = 2 AND
    Answers.OwnerUserId = @UserId
) AS MyAnswers
INNER JOIN Votes ON Votes.PostId = MyAnswers.AnswerID
WHERE Votes.VoteTypeId = 2 OR Votes.VoteTypeId = 3

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results