Graph of post score over time

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

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
begin
  set @score =
    case
      when @voteType = 2 then @score + 1
      when @voteType = 3 then @score - 1
    end
  insert into #DateScore values (@voteDate, @score)
  fetch next from VOTES into @voteType, @voteDate
end

close VOTES
deallocate VOTES

select * from #DateScore

Enter Parameters

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