You can use a subquery; you might see some improvement in performance, but
its still likely to be slow. If you have a unique date/time value per
transaction then you can base it solely on that:
SELECT TransactionDateTime, Amount,
(SELECT SUM(Amount)
FROM Transactions As T2
WHERE T2.TransactionDateTime <= T1.TransactionDateTime)
AS Balance
FROM Transactions AS T1
ORDER BY TransactionDateTime DESC;
If not, and you only have a date per transaction, then you have to bring
another uniquely valued column such as an autonumber transactionID into play
to separate transactions on the same day:
SELECT TransactionDate, Amount,
(SELECT SUM(Amount)
FROM Transactions AS T2
WHERE T2.TransactionDate <= T1.TransactionDate
AND ( T2.TransactionID <= T1.TransactionID
OR T2.TransactionDate <> T1.TransactionDate))
AS Balance
FROM Transactions AS T1
ORDER BY TransactionDate DESC, TransactionID DESC;
Note that these queries won't be updatable. Calling the DSum function
rather than using a subquery is generally only done if an updatable query is
required.
Ken Sheridan
Stafford, England