Hi,
I have a date range which I like to group by months, but not from the 1st to last date of the calendar month but by given start date. For example the table below represents the date range with some values in a table. So the first month range in the group should be from 06/06/2013 to 08/07/2013. The 06/07/2013 is absent because it's Saturday. In fact the data is populated with working days only.
Table below shows what I really would like to get:
There is a simple calculation for each month anniversary date, if the value from the start date, 06/06/2013, here 12 is less than the next month anniversary date, 08/07/2013, which is 9, then it should ignore it. And only show the value from the month who's anniversary date value is less than the first date value, 12. So the example above shows value 14 for the second month's anniversary date, 06/08/2013. If the value has been found in any month the show, and ignore the rest. I am just interested if there are any and report which number of month and the value.
I can implement this in procedural way, such as in VBA, but because the above looped many times it will take hours to run the process. I have tried in SQL Server, but first problem I came up with is that I can't group by month from the given start date.
Is this possible to do in T-SQL ?