I have to implement a solution where two date ranges can overlap each other. within the overlapped dates, I have to count how many days overlap each other. Once I know the overlapped days I can calculate a total figure based on the price that’s attached per day.
A scenario would be that
A customer is booking a hotel
Customer booking dates – 17/02/2011 to 26/02/2011
Normal price (All year) – 01/01/2011 – 31/12/2011 (price per day :$30.00)
Special Offer 1 dates – 01/01/2011 to 19/02/2011 (price per day :$20.00)
Special Offer 2 dates – 17/02/2011 to 24/02/2011 (price per day :$10.00)
In the above scenario, the proposed algorithm should work out the cheapest offer that the date ranges overlap and work out the price for the booking. If there is no special offer available it uses the normal price.
So for the first two days the system should get the price from “special offer 1” as it’s the cheapest available price. Next 5 days should be “Special offer 2 price” and for the next 2 days it’ll be normal price.
I’d be grateful to see both SQL(using MS-SQL Server) or Code base answers to get the diffrenet views.
I hope the question is clear and looking foward to see the answers.
Many thanks in advance
Let’s supose that for each day you should apply lowest price.
then you can call function in your query: