I have a exchange rate table like below

```
FromCurrency    ToCurrency          ValidFrom               ExchangeRate
USD             ZAR         2012-01-05 00:00:00.000         7.7260000000
USD             ZAR         2012-01-04 00:00:00.000         7.6740000000
USD             ZAR         2012-01-03 00:00:00.000         7.4601000000
USD             ZAR         2012-01-02 00:00:00.000         7.7600000000
USD             ZAR         2012-01-01 00:00:00.000         8.0945000000
EUR             NOK         2012-01-05 00:00:00.000         7.5881000000
EUR             NOK         2012-01-04 00:00:00.000         7.5974000000
EUR             NOK         2012-01-03 00:00:00.000         7.4494000000
EUR             NOK         2012-01-02 00:00:00.000         7.6606000000
EUR             NOK         2012-01-01 00:00:00.000         7.7740000000
USD             AED         2012-01-05 00:00:00.000         3.6731000000
USD             AED         2012-01-04 00:00:00.000         3.6731000000

```

My main table is 

```
Transaction Date    Amount  Currency    FromCurrency
13971   5/27/2011    8000     USD   USD
13971   7/31/2011   -6809.4   ZAR   USD
13971   8/30/2011   -425.59   ZAR   USD
13971   9/27/2011   -6809.4   ZAR   USD
67467   11/8/2011    5000     GBP   GBP
67467   12/21/2011  -5195.06  ZAR   GBP
67467   1/30/2012   -5195.06  ZAR   GBP
81181   4/15/2011    6000     USD   USD
81181   6/28/2011   -5159.03  ZAR   USD
82418   10/21/2011   5000     EUR   EUR
82418   1/27/2012   -3919.97  NOK   EUR

```

Above is sample data of table, my actual table has millions of records. I have to multiply amount with exchange rate column (from exchange rate table) and update the corresponding FromCurrency (from exchange rate table) with currency column in my table.

I have tried many ways but couldn't find the solution. The tricky part here is there is not matching date for my table in exchange rate table.

Exchange rate should be applied like this. If my transaction date is Feb-20-2012 and Currency is ZAR and FromCurrency is USD then I have to pick the below row from exchange rate table

```
USD             ZAR         2012-01-02 00:00:00.000         7.7600000000

```