Q&A for amateur radio enthusiasts
declare @weight_threshold int = 10 declare @score_cap int = 10 declare @min_len int = 15 declare @len_step int = 15 declare @len_cap int = 9 declare @age_cap int = 10 select ( SELECT (case when score is null then 0 when score < @score_cap then score else @score_cap end + case when (len(Text) - @min_len)/@len_step < @len_cap then (len(Text) - @min_len)/@len_step else @len_cap end + case when cast(GetUTCDate() - CreationDate as int) < @age_cap then @age_cap - cast(GetUTCDate() - CreationDate as int) else 0 end ) ) as Weight, Id as [Comment Link], UserId as [User Link], Creationdate, Score, (len(Text) - @min_len)/@len_step length, @age_cap - cast(GetUTCDate() - CreationDate as int) age from Comments where PostId = ##PostId## order by Weight DESC,CreationDate DESC;