I need to create a new table based on bookings placed in our system.
Currently the booking information contains data like:-
BookingID StartDate EndDate Amount
1 01/01/2005 31/03/2005 £100
2 15/02/2005 16/03/2005 £50
I need to split these lines up based on the start and end dates. This will be used to charge the client on a monthly basis as follows:-
BookingID MonthStart MonthEnd Amount
1 01/01/2005 31/01/2005 £33.33
1 01/02/2005 28/02/2005 £33.33
1 01/03/2005 31/03/2005 £33.33
2 15/02/2005 28/02/2005 £25.00
2 01/03/2005 16/03/2005 £25.00
I know this is probably easier in VB.net or similar, but it would be nice to do this in a stored procedure.
Has anyone ever done anything like this before in Transact-SQL?
Thanks
Currently the booking information contains data like:-
BookingID StartDate EndDate Amount
1 01/01/2005 31/03/2005 £100
2 15/02/2005 16/03/2005 £50
I need to split these lines up based on the start and end dates. This will be used to charge the client on a monthly basis as follows:-
BookingID MonthStart MonthEnd Amount
1 01/01/2005 31/01/2005 £33.33
1 01/02/2005 28/02/2005 £33.33
1 01/03/2005 31/03/2005 £33.33
2 15/02/2005 28/02/2005 £25.00
2 01/03/2005 16/03/2005 £25.00
I know this is probably easier in VB.net or similar, but it would be nice to do this in a stored procedure.
Has anyone ever done anything like this before in Transact-SQL?
Thanks