We have a table which holds exchange rates for various currencies:
If I were retrieving all rates for a currency I would use:
However, I want to find the rate at a particular date.
EG.
VALID_FROM RATE
2005-01-01 10
2005-02-01 10.5
2005-03-01 9.8
2005-04-01 10.1
If the requested date were 2005-02-19 the rate should be 10.5
If the requested date were 2005-02-01 the rate should be 10.5
If the requested date were 2005-03-01 the rate should be 9.8
If the requested date were 2005-04-02 the rate should be 10.1
If the requested date were 2006-02-22 the rate should be 10.1
Anhy ideas if this can be done in a single SQL statement, please?
thanks
Applications Support
UK
Code:
SQL> desc currency_rate_tab
Name Null? Type
----------------------------------------- -------- -----------------
COMPANY NOT NULL VARCHAR2(20)
VALID_FROM NOT NULL DATE
CURRENCY_TYPE NOT NULL VARCHAR2(10)
CURRENCY_CODE NOT NULL VARCHAR2(3)
CURRENCY_RATE NUMBER
ROWVERSION NOT NULL DATE
CONV_FACTOR NOT NULL NUMBER
REF_CURRENCY_CODE NOT NULL VARCHAR2(3)
If I were retrieving all rates for a currency I would use:
Code:
select currency_rate from currency_rate_tab cr where
cr.COMPANY=&COMP and
cr.CURRENCY_CODE=&CURR and
cr.CURRENCY_TYPE='1'
However, I want to find the rate at a particular date.
EG.
VALID_FROM RATE
2005-01-01 10
2005-02-01 10.5
2005-03-01 9.8
2005-04-01 10.1
If the requested date were 2005-02-19 the rate should be 10.5
If the requested date were 2005-02-01 the rate should be 10.5
If the requested date were 2005-03-01 the rate should be 9.8
If the requested date were 2005-04-02 the rate should be 10.1
If the requested date were 2006-02-22 the rate should be 10.1
Anhy ideas if this can be done in a single SQL statement, please?
thanks
Applications Support
UK