How many upvotes do I have for each tag (with Google Chart)

0

Please login or register to vote for this query.

(click on this box to dismiss)

Modified Sam's query to test Google Charts embedding

Stack Overflow

Q&A for programmers

-- How many upvotes do I have for each tag?
-- how long before I get tag badges?

DECLARE @UserId int = ##UserId##

SELECT TOP 15 
    TagName,
    COUNT(*) AS UpVotes 
INTO #orig    
FROM Tags
    INNER JOIN PostTags ON PostTags.TagId = Tags.id
    INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
    INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2
WHERE 
    Posts.OwnerUserId = @UserId
GROUP BY TagName 
ORDER BY UpVotes DESC

DECLARE @TagList varchar(8000)
SELECT @TagList = COALESCE(@TagList + '%7c', '') + TagName
FROM #orig

DECLARE @VotesList varchar(8000)
SELECT @VotesList = COALESCE(@VotesList + ',', '') + CAST(UpVotes AS varchar(100))
FROM #orig

DECLARE @VotesLabels varchar(8000)
SELECT @VotesLabels = COALESCE(@VotesLabels + '%7c', '') + CAST(UpVotes AS varchar(100))
FROM #orig

SELECT 'http://chart.apis.google.com/chart?cht=p&chco=FF0000,FFFF00%7cFF8000,00FF00%7c00FF00,0000FF&chs=450x275&chd=t:'
       +@VotesList+'&chl='+@VotesLabels+'&chdl='+@TagList+'|Show the Chart' [TagName], NULL [UpVotes]
UNION ALL SELECT TagName, UpVotes FROM #orig

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached