straatlang
Technical User
I hope somebody can help me with the next problem.
Table: movements.
Value Date Account Amount Cur DRCR
1-1-2003 123 2000 EUR CR
1-2-2003 456 1500 EUR CR
1-2-2003 123 1450 USD CR
1-4-2003 456 1250 EUR CR
1-7-2003 123 800 USD CR
15-1-2003 123 950 EUR CR
20-1-2003 789 5000 USD CR
27-1-2003 456 5000 USD CR
28-1-2003 456 3000 USD CR
29-1-2003 123 10000 EUR DT
Table :names
Account Name
123 ABC
456 DEF
789 GHJ
Table : rates
CurID Erate
EUR 1
USD 0.98
GBP 0.34
The query I am using now works properly but not if there is one rate per currency per day.
I am using the following Query (thanks to Rudy R937)
SELECT Movements.Account, Abs(Sum(Amount*IIf(DRCR='CR',1,-1))) AS Balance, Movements.Cur, IIf(Sum(Amount*IIf(DRCR='CR',1,-1))>0,'CR','DR') AS FLAG, [Enter Value Date] AS SelectedDate, Rates.Erate, Names.Name, [Erate]*[Balance] AS V_EURO
FROM (Movements INNER JOIN [Names] ON Movements.Account = Names.Account) INNER JOIN Rates ON Movements.Cur = Rates.CurID
WHERE (((Movements.[Value Date])<=DateValue([Enter Value Date])))
GROUP BY Movements.Account, Movements.Cur, Rates.Erate, Names.Name;
So the table rates now looks like this.
CurID Erate RateDate
EUR 1 01-01-2003
USD 0.95 01-01-2003
GBP 0.65 02-01-2003
USD 0.98 02-01-2003
GBP 0.66 03-01-2003
USD 0.98 03-01-2003
GBP 0.34 03-01-2003
ect
The query should show the balances per account per currency per <=Valuedate. And the balance as
EUR
The expected outcome per valuedate should be:
Account Name Balance Cur FLAG SelectedDate Erate V_EURO
123 ABC 7050 EUR DR 1 7050
123 DEF 2250 USD CR 0.98 2205
456 DEF 2750 EUR CR 1 2750
456 DEF 8000 USD CR 0.98 7840
789 GHJ 5000 USD CR 0.98 4900
Regards
Straatlang
Table: movements.
Value Date Account Amount Cur DRCR
1-1-2003 123 2000 EUR CR
1-2-2003 456 1500 EUR CR
1-2-2003 123 1450 USD CR
1-4-2003 456 1250 EUR CR
1-7-2003 123 800 USD CR
15-1-2003 123 950 EUR CR
20-1-2003 789 5000 USD CR
27-1-2003 456 5000 USD CR
28-1-2003 456 3000 USD CR
29-1-2003 123 10000 EUR DT
Table :names
Account Name
123 ABC
456 DEF
789 GHJ
Table : rates
CurID Erate
EUR 1
USD 0.98
GBP 0.34
The query I am using now works properly but not if there is one rate per currency per day.
I am using the following Query (thanks to Rudy R937)
SELECT Movements.Account, Abs(Sum(Amount*IIf(DRCR='CR',1,-1))) AS Balance, Movements.Cur, IIf(Sum(Amount*IIf(DRCR='CR',1,-1))>0,'CR','DR') AS FLAG, [Enter Value Date] AS SelectedDate, Rates.Erate, Names.Name, [Erate]*[Balance] AS V_EURO
FROM (Movements INNER JOIN [Names] ON Movements.Account = Names.Account) INNER JOIN Rates ON Movements.Cur = Rates.CurID
WHERE (((Movements.[Value Date])<=DateValue([Enter Value Date])))
GROUP BY Movements.Account, Movements.Cur, Rates.Erate, Names.Name;
So the table rates now looks like this.
CurID Erate RateDate
EUR 1 01-01-2003
USD 0.95 01-01-2003
GBP 0.65 02-01-2003
USD 0.98 02-01-2003
GBP 0.66 03-01-2003
USD 0.98 03-01-2003
GBP 0.34 03-01-2003
ect
The query should show the balances per account per currency per <=Valuedate. And the balance as
EUR
The expected outcome per valuedate should be:
Account Name Balance Cur FLAG SelectedDate Erate V_EURO
123 ABC 7050 EUR DR 1 7050
123 DEF 2250 USD CR 0.98 2205
456 DEF 2750 EUR CR 1 2750
456 DEF 8000 USD CR 0.98 7840
789 GHJ 5000 USD CR 0.98 4900
Regards
Straatlang