I have a dataset that looks like this:
ResourceID RequirementId ProjectID Startdate EndDate BillingPercentage
-------------------- -------------------- ---------- ---------- ----------------------- ----------------- ------ ---------------------------------------
1 5066 7505 2015-09-15 00: 00: 00.000 2015-09-30 00: 00: 00.000 50
2 4748 7499 2015-09-10 00: 00: 00.000 2015-09-20 00: 00: 00.000 50
I want to calculate the range and the corresponding billing% for this particular month, which is my request:
INSERT INTO @DateTimeline
SELECT @MonthStartDate AS OSTARTDATE, @ MonthEndDate AS OENDDATE, 0
INSERT INTO @DateTimeline
SELECT Startdate AS OSTARTDATE, EndDate AS OENDDATE, BillingPercentage From @RESOURCE_UNBILLED Order by Startdate
INSERT INTO @DateTimeline
SELECT EndDate AS OSTARTDATE, EndDate AS OENDDATE, BillingPercentage From @RESOURCE_UNBILLED Order by Startdate
And the data is as follows:
SerialNo OSTARTDATE OENDDATE BillingPercentage
----------- ----------------------- ---------------- ------- ---------------------------------------
1 2015-09-01 00: 00: 00.000 2015-09-30 00: 00: 00.000 0
2 2015-09-10 00: 00: 00.000 2015-09-20 00: 00: 00.000 50
3 2015-09-15 00: 00: 00.000 2015-09-30 00: 00: 00.000 50
4 2015-09-20 00: 00: 00.000 2015-09-20 00: 00: 00.000 50
5 2015-09-30 00: 00: 00.000 2015-09-30 00: 00: 00.000 50
OSTARTDATE OENDDATE BillingPercentage
----------- ----------------------- ----------------------- ---------------------------------------
2015-09-01 00:00:00.000 2015-09-10 00:00:00.000 0
2015-09-10 00:00:00.000 2015-09-15 00:00:00.000 50
2015-09-15 00:00:00.000 2015-09-20 00:00:00.000 100
2015-09-20 00:00:00.000 2015-09-30 00:00:00.000 50
, , , ?