G
Guest
Hi I have two tables:
tbExchangeRates
---------------------
erCurID 1 1
erValidFrom 01-JUN-2007 01-JUL-2007
erRate 1.44 1.55
tbDeliveries
-------------------
deDate 15-JUN-2007 02-JUL-2007
deCurrency 1 1
Querry should lookup the latest valid exchange rate based on delivery date
(tbDeliveries.deDate).
my qeurry is following:
---------------------------
SELECT tbDeliveries.deDate,
(SELECT TOP 1 tbExchangeRates.erRate
FROM tbExchangeRates, tbDeliveries
WHERE ((tbExchangeRates.erValidFrom<=bDeliveries.deDate)
AND tbExchangeRates.erCurID= tbDeliveries.deCurrency))
ORDER BY tbExchangeRates.erValidFrom DESC ) AS FX_RATE
FROM tbDeliveries;
Result from the querry is:
------------------------------
deDate FX_RATE
15-JUN-2007 1.55
02-JUL-2007 1.55
I would expect result like
---------------------------------
deDate FX_RATE
15-JUN-2007 1.44
02-JUL-2007 1.55
any idea what I did wrong
thank you for your help
tbExchangeRates
---------------------
erCurID 1 1
erValidFrom 01-JUN-2007 01-JUL-2007
erRate 1.44 1.55
tbDeliveries
-------------------
deDate 15-JUN-2007 02-JUL-2007
deCurrency 1 1
Querry should lookup the latest valid exchange rate based on delivery date
(tbDeliveries.deDate).
my qeurry is following:
---------------------------
SELECT tbDeliveries.deDate,
(SELECT TOP 1 tbExchangeRates.erRate
FROM tbExchangeRates, tbDeliveries
WHERE ((tbExchangeRates.erValidFrom<=bDeliveries.deDate)
AND tbExchangeRates.erCurID= tbDeliveries.deCurrency))
ORDER BY tbExchangeRates.erValidFrom DESC ) AS FX_RATE
FROM tbDeliveries;
Result from the querry is:
------------------------------
deDate FX_RATE
15-JUN-2007 1.55
02-JUL-2007 1.55
I would expect result like
---------------------------------
deDate FX_RATE
15-JUN-2007 1.44
02-JUL-2007 1.55
any idea what I did wrong
thank you for your help