I have an Access 2010 Report derived from two tables joined by a UnionQuery for a "look like" bank statement with the following fields:
TransactionID (Primary Key)
TransactionDate
Credit
Debit
The report is based on the following SQL:
SELECT Q1.TransactionID, Q1.TransactionDate, Q1.Credit, Q1.Debit, Sum(Q2.Credit-Q2.Debit) AS Balance, Q1.Inv, Q1.Company, Q1.City, Q1.Country, Q1.ItemDescription, Q1.Currency, Q1.Amount, Q1.Currency2, Q1.PayEff, Q1.Branch, Q1.Year, Q1.Month
FROM qryAccountTransactions AS Q1 INNER JOIN qryAccountTransactions AS Q2 ON (Q2.TransactionDate<=Q1.TransactionDate) AND (Q2.TransactionID>=Q1.TransactionID Or Q2.TransactionDate<>Q1.TransactionDate)
GROUP BY Q1.TransactionID, Q1.TransactionDate, Q1.Credit, Q1.Debit, Q1.Inv, Q1.Company, Q1.City, Q1.Country, Q1.ItemDescription, Q1.Currency, Q1.Amount, Q1.Currency2, Q1.PayEff, Q1.Branch, Q1.Year, Q1.Month
ORDER BY Q1.TransactionDate DESC , Q1.TransactionID DESC;
It runs fine, providing there is only one entry with the same date. If several entries the same day, the balance is calculated randomly. The final is ok again for the next date.
As the data are coming from two separate tables, the TransactionID is not in sequence with the date, although they are Unique.
I have tried to manually put them in sequence, but the problem is the same. It is only a matter related to several entries with the same date.
Can anyone help ?
Thanks
TransactionID (Primary Key)
TransactionDate
Credit
Debit
The report is based on the following SQL:
SELECT Q1.TransactionID, Q1.TransactionDate, Q1.Credit, Q1.Debit, Sum(Q2.Credit-Q2.Debit) AS Balance, Q1.Inv, Q1.Company, Q1.City, Q1.Country, Q1.ItemDescription, Q1.Currency, Q1.Amount, Q1.Currency2, Q1.PayEff, Q1.Branch, Q1.Year, Q1.Month
FROM qryAccountTransactions AS Q1 INNER JOIN qryAccountTransactions AS Q2 ON (Q2.TransactionDate<=Q1.TransactionDate) AND (Q2.TransactionID>=Q1.TransactionID Or Q2.TransactionDate<>Q1.TransactionDate)
GROUP BY Q1.TransactionID, Q1.TransactionDate, Q1.Credit, Q1.Debit, Q1.Inv, Q1.Company, Q1.City, Q1.Country, Q1.ItemDescription, Q1.Currency, Q1.Amount, Q1.Currency2, Q1.PayEff, Q1.Branch, Q1.Year, Q1.Month
ORDER BY Q1.TransactionDate DESC , Q1.TransactionID DESC;
It runs fine, providing there is only one entry with the same date. If several entries the same day, the balance is calculated randomly. The final is ok again for the next date.
As the data are coming from two separate tables, the TransactionID is not in sequence with the date, although they are Unique.
I have tried to manually put them in sequence, but the problem is the same. It is only a matter related to several entries with the same date.
Can anyone help ?
Thanks