Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / May 2006

Tip: Looking for answers? Try searching our database.

Linking Date Based Data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dave - 30 May 2006 15:45 GMT
I have two tables - Transactions and Rates.

Table: Txns
Refce   TxnDate       Curr     Amount
10       21/03/2006    USD       10.87
11       10/04/2006    USD       20.00

Table: Rates
Curr      RateDate       Rate
EUR      01/01/2006    1.41
USD      01/01/2006    1.80
USD      01/03/2006    1.81
USD      01/04/2006    1.82
USD      01/05/2006    1.83

I want to link these tables in a Query so that I can value the
transactions using the currency rate in force at the transaction date.
In this example, for Refce=10, the rate should be 1.81; for Refce=11,
it should be 1.82.

If only a forward dated rate is found, it should be ignored.

All dates are ddmmyyyy

Can this be done in a single Query?
Can anyone help with the SQL please?

Thanks
Dave
KARL DEWEY - 30 May 2006 17:15 GMT
Try this with the first query named TxnsRateDate --

SELECT Txns.Refce, Txns.TxnDate, Txns.Curr, Txns.Amount, Max(Rates.RateDate)
AS MaxOfRateDate
FROM Txns INNER JOIN Rates ON Txns.Curr = Rates.Curr
WHERE (((Rates.RateDate)<=[TxnDate]))
GROUP BY Txns.Refce, Txns.TxnDate, Txns.Curr, Txns.Amount;

SELECT TxnsRateDate.Refce, TxnsRateDate.TxnDate, TxnsRateDate.Curr,
TxnsRateDate.Amount, Rates.Rate
FROM Rates INNER JOIN TxnsRateDate ON (Rates.Curr = TxnsRateDate.Curr) AND
(Rates.RateDate = TxnsRateDate.MaxOfRateDate);

> I have two tables - Transactions and Rates.
>
[quoted text clipped - 25 lines]
> Thanks
> Dave
dave - 31 May 2006 08:17 GMT
Thanks Karl

I had been hoping for a single Query, but I guess that's not possible
given that I need the rate associated with the latest rate date.

Dave
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.