Graph of post score over time


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @score as int = 0

declare @voteType as int
declare @voteDate as date

create table #DateScore (
  VoteDate date not null,
  Score int not null

declare VOTES cursor for
  select Votes.VoteTypeId, Votes.CreationDate
  from Votes
  where Votes.PostId = ##PostId##
  and Votes.VoteTypeId in (2, 3) -- upvote and downvote
  order by Votes.CreationDate

open VOTES

fetch next from VOTES into @voteType, @voteDate
while @@FETCH_STATUS = 0
  set @score =
      when @voteType = 2 then @score + 1
      when @voteType = 3 then @score - 1
  insert into #DateScore values (@voteDate, @score)
  fetch next from VOTES into @voteType, @voteDate

close VOTES
deallocate VOTES

select * from #DateScore

Enter Parameters

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