Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Mar 25, 1997

Finding the Correct Row Based on Effective Date

Question:
I have a table with three columns: the first contains the name of the currency, the second contains the currency rate and the third contains the actual date when the currency rate changed. They are in no particular order, neither by currency, rate or date. My question is: how can I select a specific date and return the currency rate in effect for that date?

For example, the data might look like this:

    DEM   5.76   01/19/96
    DKK   1.32   01/04/96
    DEM   5.92   02/09/96
    BEF   0.33   04/04/96
    DEM   5.88   01/04/96
    ...   ....   ........
How do I retrieve the actual currency rate for Deutche Mark, DEM, for January 20, 1996? (The answer should be 5.76.)

Answer:
Try this:

    SELECT value FROM Currencies
        WHERE currency='DEM' AND
        chg_date IN 
            (SELECT MAX(chg_date) FROM Currencies
                WHERE chg_date <='01/20/96'); 
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date