Q&A about the site for members of the workforce navigating the professional setting
DECLARE @STARTDATE DATETIME = '2015-07-01 00:00:00'; DECLARE @ENDDATE DATETIME = '2015-08-31 23:59:59'; DECLARE @NewLineChar AS CHAR(2) = CHAR(13); declare @varDATE int = 2018; -- 03-31, 05-31, 07-31, 08-31, 10-31, 12-31 with cteQuestions (id, AcceptedAnswerId) as ( SELECT id, AcceptedAnswerId FROM Posts AS Question where Question.Tags LIKE '%java%' AND --Question.Body LIKE '%<code>%' and posttypeid = 1 and question.creationdate BETWEEN @STARTDATE AND @ENDDATE and AcceptedAnswerId is not null --and id = 18731465 and id not in ( SELECT d.id FROM Posts d -- d=duplicate LEFT JOIN PostHistory ph ON ph.PostId = d.Id LEFT JOIN PostLinks pl ON pl.PostId = d.Id LEFT JOIN Posts o ON o.Id = pl.RelatedPostId -- o=original WHERE d.PostTypeId = 1 -- 1=Question AND pl.LinkTypeId = 3 -- 3=duplicate AND ph.PostHistoryTypeId = 10 -- 10 = vote Close the Post and datepart(year,d.creationdate) <= @varDATE ) ) select cast(answeres.Id as varchar(20))+'<postid>'+answeres.Body from posts answeres inner join ctequestions questions on answeres.id = questions.AcceptedAnswerId --and answeres.posttypeid = 2 where datepart(year,answeres.creationdate) <= @varDATE and answeres.Body LIKE '%<code>%' order by answeres.Id