I made this query to create a graph of a user's popular questions and the view count on that question. It allows for a minimum of 500
views, and a score of 3
.
DECLARE @allowed_min_views INT = 500;
DECLARE @allowed_min_score INT = 3;
DECLARE @user_id INT = ##UserId:int?-1##;
DECLARE @min_views INT = ##MinimumViews:int?500##;
DECLARE @min_score INT = ##MinimumScore:int?3##;
DECLARE @question INT = 1;
IF (@min_views < @allowed_min_views)
BEGIN
PRINT '@MinimumViews must be larger than 499.'
END
IF (@min_score < @allowed_min_score)
BEGIN
PRINT '@MinimumScore must be larger than 2.'
END
IF (@min_views >= @allowed_min_views AND @min_score >= @allowed_min_score)
BEGIN
SELECT
ViewCount
, Score
FROM Posts WHERE
PostTypeId = @question
AND OwnerUserId = @user_id
AND ViewCount >= @min_views
AND Score >= @min_score
ORDER BY ViewCount ASC;
END
Finally, here's some sample input (I'm using @Mat'sMug's user ID):
@user_id: 23788
@min_views: 500
@min_score: 7