I am just finding a way to get a list of Start Week and End Week between two date range.
For e.g. if I call a function or a stored procedure say
GetWeekDates ('21 Mar 2014','21 Mar 2014')
Then I should get a table as:
Start Week | End Week
17 March 2014 | 23 Mar 2014
24 March 2014 | 30 Mar 2014
....
I don't want to use CURSOR or WHILE Loop.
Any direction where I should lead to?
I am just doing a re factor on existing code.
Kind regards, Am
I end up going through WITH statement and it is much faster than any other way; refactor mission accompliseded
Here is how you can call:
This will work as long as the intervals are 38 years or less. It will offer better performance and it does not rely on the local setting of the server.
This setting will cause your script to return wrong result:
This means your local setting currently conflicts with your needs and your code is compensating.
Here is the script. The script is limited to 38 years for performance reasons (I find it unlikely that you need bigger intervals than that). It will be fairly easy to extend it to more years.
Result: