Popular Questions By View Count

0

Please login or register to vote for this query.

(click on this box to dismiss)

Code Review

Q&A for peer programmer code reviews

DECLARE @allowed_min_views INT = 500;
DECLARE @allowed_min_score INT = 3;

DECLARE @user_id INT = ##UserId:int?-1##;
DECLARE @min_views INT = ##MinViews:int?500##;
DECLARE @min_score INT = ##MinScore: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
    , [User Link] = @user_id
    , [Post Link] = Id
    , CreationDate
    , [Tags] = Tags
    FROM Posts 
    WHERE
      PostTypeId = @question
      AND OwnerUserId = @user_id
      AND ViewCount >= @min_views
      AND Score >= @min_score
    ORDER BY ViewCount DESC;
END

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results