실행 날짜 목록을 작성하여 위에있는 날짜까지 6 주를 더하고 싶습니다. 지금까지 제 코드는 저에게 시작일과 종료일을 알려줍니다. 나는 시작과 끝 사이에 6 개 주 간격을 표시해야하는 것은이 ENDDATE 전에 마지막 날짜에 도달 할 때까지SQL SERVER에서 누적 합계를 얻으십시오
aLearnerRef startdate enddate reviewdate
------------------------------------------------------
399750423600 2013-11-27 2014-06-12 2014-01-08
399750423600 2013-11-27 2014-06-12 2014-02-19
399750423600 2013-11-27 2014-06-12 2014-04-02
399750423600 2013-11-27 2014-06-12 2014-05-14
내가 루프에 원하는 날짜. 나는 이것을 할 수있는 방법을 찾지 못한다.
SELECT a.aLearnerRef, x.startdate, x.enddate
FROM aims a
inner join vStudyP s
on s.LearnerRef = a.aLearnerRef
join (SELECT aLearnerRef, min(learnstartdate) startdate, max(learnplannedenddate) enddate
FROM aims
GROUP BY aLearnerRef) x
on a.aLearnerRef = x.aLearnerRef
group by a.aLearnerRef, x.startdate, x.enddate
재귀 CTE가 유용하다고 생각합니다. 일부 코드 및 공유를 시도합니다. – AK47