Worst Case Scenario - How long until the Electorate Badge

0

Please login or register to vote for this query.

(click on this box to dismiss)

Assuming that none of my votes are for questions, how many days until I get the Electorate badge.

スタック・オーバーフロー

プログラマーとプログラミングに熱心な人々のための質問と回答

-- Worst Case Scenario - How long until the Electorate Badge
-- Assuming that none of my votes are for questions, how many days
-- until I get the Electorate badge.


declare @UserId int = ##UserId##
declare @voteCount int

select @voteCount = u.UpVotes + u.DownVotes
from Users u
where u.Id = @UserId

-- using equivalent of max given by this answer: http://stackoverflow.com/questions/124417/is-there-a-max-function-in-sql-server-that-takes-two-values-like-math-max-in-net/293804#293804

select case
    when @voteCount < 600 then ceiling(0.5 * ((600 - @voteCount)/30.0 + 5) + ((600 - @voteCount)/30.0 - 5))
    when exists(select 1 from Badges where UserId = @UserId and Name = 'Electorate') then 0
    else ceiling(@voteCount / (4 * 30.0))
end
as ElectorateState

Enter Parameters

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