I work with SQL Server 2005. I have a start and end date.
Ex:
START_DATE END_DATE
2011-04-24 2012-05-05
I want to get all the start day (SQL is set so that it’s sunday) and end day (saturday) of each week between the two dates.
Desired result :
2011-04-24 2011-04-30
2011-05-01 2011-05-07
2011-05-08 2011-05-14
....
2012-04-29 2012-05-05
Now I know I could do something like DATEADD(week, 1, 2011-04-24) until I get to my end date, but I don’t quite see how to do it until I get to my end date (without having a cursor or a while). I would like to do it in one query.
Can anyone help?
Just found a way to do it with recursivity!