Home SQL Input Date Range to work out Rate per day

# SQL Input Date Range to work out Rate per day

user4245
1#
user4245 Published in September 21, 2018, 8:03 am

Hi can anyone help me with the T-SQL query required to produce a rate per day based on two tables as below:

I have one table containing ranges:

FromDate   | ToDate
2017-06-20   2017-07-01


and one table containing rates (This table is not limited to 2 records):

FromDate     | Rate
2017-06-11     400
2017-06-24     1200


Based on the range from the first table I need to produce a result set as follows which returns the rate for each date in the input range:

Date        |  Rate
2017-06-20     400
2017-06-21     400
2017-06-22     400
2017-06-23     400
2017-06-24     1200
2017-06-25     1200
2017-06-26     1200
2017-06-27     1200
2017-06-28     1200
2017-06-29     1200
2017-06-30     1200
2017-07-01     1200


I will then need to sum the rate in a later step to produce a total.