I have table of the following form

```
Name    Currency    Rate    Effective date
Institution 1   USD 0.25    Sunday, June 05, 2016
Institution 1   CAD 0.35    Monday, December 05, 2016
Institution 1   USD 0.5 Monday, April 03, 2017
Institution 2   USD 0.25    Sunday, August 07, 2016
Institution 2   USD 0.28    Sunday, January 15, 2017
Institution 2   CAD 0.35    Saturday, April 20, 2013
Institution 2   CAD 0.25    Monday, March 06, 2017

```

I need a query in SQL Server grouped for each institution and currency, get the rate for effective date between start date and end date. If there is no effective date between declared start date and end date then look for the last effective date lower than start date and get the corresponding rate e.g. If start date is Jan 1, 2017 and end date is Mar 31, 2017 then for Institution 1, USD Rate will be 0.25 and CAD Rate will 0.35. Similarly for start date Apr 1, 2017 and end date May 31, 2017 USD Rate will be 0.5 and CAD Rate will be 0.35.

Any help will be highly appreciated!