RedJessie
asked on
splitting a time period into calendar months-Oracle SQL
Hi
I've got a table that holds a series of rows to do with billing periods & cost, like so:-
ACC_NUM ST_DT END_DT DAYS COST AVG_DAILY_COST
264001440 07/16/2008 09/16/2008 62 103.65 1.67
264001440 09/16/2008 11/13/2008 58 127.11 2.19
264001440 11/13/2008 01/16/2009 64 205.78 3.22
264001440 01/16/2009 03/20/2009 63 176.07 2.79
264001440 03/20/2009 05/18/2009 59 125.09 2.12
264001440 05/18/2009 07/20/2009 63 98.81 1.57
When the number of days in the period is > 34, the cost has to be broken out by calendar month, with the following guidelines.
Example: Billing Period is 05/18/2009 to 07/20/2009 and the amount is 98.81 dollars.
Number of days in the billing period is 63 days. average daily cost is $1.57.
The amount assigned to May 2009 is 1.57 * 13 days = 20.41 USD.
The amount assigned to June 2009 is 1.57 * 30 days = 47.10 USD.
The amount assigned to July 2009 is 98.81-20.41-47.10 = 31.30 (subtraction avoids rounding errors).
There would also need to be a portion of the previous 2 month bill allocated to May 2009.
I'm envisioning this data transformed into a new table, with the account number and 12 columns, 1 for each calendar month.
I'm not sure whether its best to label the 12 columns as the actual months, or to be non-specific, given that I'm dealing with a rolling 12 months. ie will be a different data set each month during dev & testing till the final cut-over in Jan 2010.
has anyone done something like this before? I'd appreciate whatever help is on offer.
Many Thanks
Red
I've got a table that holds a series of rows to do with billing periods & cost, like so:-
ACC_NUM ST_DT END_DT DAYS COST AVG_DAILY_COST
264001440 07/16/2008 09/16/2008 62 103.65 1.67
264001440 09/16/2008 11/13/2008 58 127.11 2.19
264001440 11/13/2008 01/16/2009 64 205.78 3.22
264001440 01/16/2009 03/20/2009 63 176.07 2.79
264001440 03/20/2009 05/18/2009 59 125.09 2.12
264001440 05/18/2009 07/20/2009 63 98.81 1.57
When the number of days in the period is > 34, the cost has to be broken out by calendar month, with the following guidelines.
Example: Billing Period is 05/18/2009 to 07/20/2009 and the amount is 98.81 dollars.
Number of days in the billing period is 63 days. average daily cost is $1.57.
The amount assigned to May 2009 is 1.57 * 13 days = 20.41 USD.
The amount assigned to June 2009 is 1.57 * 30 days = 47.10 USD.
The amount assigned to July 2009 is 98.81-20.41-47.10 = 31.30 (subtraction avoids rounding errors).
There would also need to be a portion of the previous 2 month bill allocated to May 2009.
I'm envisioning this data transformed into a new table, with the account number and 12 columns, 1 for each calendar month.
I'm not sure whether its best to label the 12 columns as the actual months, or to be non-specific, given that I'm dealing with a rolling 12 months. ie will be a different data set each month during dev & testing till the final cut-over in Jan 2010.
has anyone done something like this before? I'd appreciate whatever help is on offer.
Many Thanks
Red
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER