If I have a table containing schedule information that implies specific dates, is there an SQL statement that can be written to convert this information into real rows using some kind of CROSS JOIN, maybe?
Consider a payment schedule table with these columns:
- StartDate - start date of the schedule (the first payment should be sent on this date)
- Duration - months length of the schedule
- Frequency - the number of months between repetitions
- PaymentAmt - payment amount: -)
SchedID StartDate Term Frequency PaymentAmt
-------------------------------------------------
1 05-Jan-2003 48 12 1000.00
2 20-Dec-2008 42 6 25.00
Is there one SQL statement that allows me to move from the above to the next?
Running
SchedID Payment Due Expected
Num date total
--------------------------------------
1 1 05-Jan-2003 1000.00
1 2 05-Jan-2004 2000.00
1 3 05-Jan-2005 3000.00
1 4 05-Jan-2006 4000.00
1 5 05-Jan-2007 5000.00
2 1 20-Dec-2008 25.00
2 2 20-Jun-2009 50.00
2 3 20-Dec-2009 75.00
2 4 20-Jun-2010 100.00
2 5 20-Dec-2010 125.00
2 6 20-Jun-2011 150.00
2 7 20-Dec-2011 175.00
MS SQL Server 2005 ( ), , while, , - CROSS JOIN , .
.
EDIT: SQL Server 2005, 2000. , . .