I have a date range where a start date is 2 years prior to today. e.g.) '05/29/2007' ~ '05/29/2009'.
How can I break above date range so that I would get a list like the following?
(start date starts with "05/27/2007", not "05/29/2007" since the start of weekday is Sunday and '05/27/2007' is the first day of week for '05/29/2007' and the same reasoning for the last EndDate, 05/30/2009, which is Saturday)
StartDate EndDate
05/27/2007 06/02/2007
06/03/2007 06/09/2007
...
05/24/2009 05/30/2009
[UPDATE] here is my final query
WITH hier(num, lvl) AS (
SELECT 0, 1
UNION ALL
SELECT 100, 1
UNION ALL
SELECT num + 1, lvl + 1
FROM hier
WHERE lvl < 100
)
SELECT num, lvl,
DATEADD(dw, -DATEPART(dw, '2007-05-29'), '2007-05-29') + num * 7,
DATEADD(dw, -DATEPART(dw, '2007-05-29'), '2007-05-29') + (num + 1) * 7
FROM hier
where num <= 104 --; 52 weeks/year * 2
ORDER BY num