Hello and thank you for your help I am creating a View in SQL 2008, I need to convert amounts into a different currency, I also need to make sure it is using the appropriate currency based on date. Before I went with just creating an average of the Month to simplify my conversion but I think having each field calculated individually is better.
The Data from my currency table looks like so(simplified) TABLE A.
HOMECUR SOURCECUR RATEDATE RATE
USD CAD 20120314 1.0086000
USD CAD 20120316 1.0087000
The Data from the amount table looks like so(simplified) TABLE B.
RATEDATE TRANSAMT FISCALYR FISCALPERD ACCTID
20120314 120.00 2012 05 123456
So my question is, what can I put to have the RATE that matches the RATEDATE and if that does not exist the RATEDATE the next RATEDATE just before.
Overall, I am grouping data by acctID, FISCALYR and FISCALPERD and SUMing the conveted amounts, but I decided to convert the amounts before SUMing them with a WITH statement.
ALTER VIEW vJFTESTVIEW
AS
WITH
ActualRateHAIUSA as(
SELECT POP = rat.RATE * act.TRANSAMT,
act.FISCALYR,
act.FISCALPERD,
act.ACCTID as ACID
FROM
TABLEA rat,
TABLEB act
WHERE -- as my table shows TABLE B's RATEDATE is on the 15th of March
--, while TABLE A does not have the 15th of March.
--It should then take the one 14h instead
--(the next closest date while not going the original date)
AND rat.HOMECUR = 'CAD'
AND rat.SOURCECUR = 'USD'
)
Any suggestion would be greatly appreciated.