Answers created in Q2 - 2015

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- Quarter: Enter the quarter of the year. Must be a number from 1-4.
-- Year: Enter the year, must a number, e.g. 2015.

DECLARE @Quarter int = ##Quarter:int?1##, @Year int = ##Year:int?2015##;

DECLARE @StartDate date =
  CASE @Quarter
    WHEN 1 THEN CAST(CAST(@Year AS varchar) + '-01-01' AS date)
    WHEN 2 THEN CAST(CAST(@Year AS varchar) + '-04-01' AS date)
    WHEN 3 THEN CAST(CAST(@Year AS varchar) + '-07-01' AS date)
    WHEN 4 THEN CAST(CAST(@Year AS varchar) + '-10-01' AS date)
    ELSE CAST('2015-01-01' AS date)
   END;
   
DECLARE @EndDate date=
  CASE @Quarter
    WHEN 1 THEN CAST(CAST(@Year AS varchar) + '-03-31' AS date)
    WHEN 2 THEN CAST(CAST(@Year AS varchar) + '-06-30' AS date)
    WHEN 3 THEN CAST(CAST(@Year AS varchar) + '-09-30' AS date)
    WHEN 4 THEN CAST(CAST(@Year AS varchar) + '-12-31' AS date)
    ELSE CAST(CAST(@Year AS varchar) + '-12-31' AS date)
   END;

SELECT
  Posts.Id AS [Post Link],
  ParentPost.Title AS [Question],  
  Posts.CreationDate AS [Date Created],
  Users.Id AS [User Link],
  Posts.Score,
  CASE WHEN ParentPost.AcceptedAnswerId = Posts.Id THEN 'Yes' ELSE 'No' END AS [Is Accepted]
FROM Posts
  INNER JOIN Users
    ON Posts.OwnerUserId = Users.Id
  INNER JOIN Posts AS ParentPost
    ON Posts.ParentId = ParentPost.Id
    WHERE CAST(Posts.CreationDate AS Date) BETWEEN @StartDate AND @EndDate
  -- Answers only
  AND Posts.PostTypeId = 2
ORDER BY Posts.CreationDate;

Enter Parameters

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