SQL query to show what has been payed each
- by Tommy Jakobsen
I'm looking for help to create a query, to solve the following problem:
Let's imagine the row:
Name StartDate EndDate Payed
James 10-10-2010 17-02-2011 860
Now I need a way to split this row up, so I can see what he pays every month, for his period, a query that returns:
Name Year Month Payed
James 2010 10 172
James 2010 11 172
James 2010 12 172
James 2011 01 172
James 2010 02 172
There are lots of different customers with different StartDate/EndDate and amount payed, so the query has to handle this aswell. How can I do this in SQL (MS SQL Server 2005)?
Help will be much appreciated!