I have a query, and I want a field that shows the current balance as of that transaction, eg:
_________________________________________________________
|__Transaction ID__|__Type_______|__Amount__|__Balance__|
|__1______________|__Deposit_____|__£10______|__£10_______|
|__2______________|__Deposit_____|__£30______|__£40_______|
|__3______________|__Withdrawal__|__£15______|__£25_______|
So far, I have this:
Although this does not look at the 'Type' field; it just adds the amounts; regardless of it being a deposit or withdrawal. I'm really not sure how to add this.
Thanks in advance.
_________________________________________________________
|__Transaction ID__|__Type_______|__Amount__|__Balance__|
|__1______________|__Deposit_____|__£10______|__£10_______|
|__2______________|__Deposit_____|__£30______|__£40_______|
|__3______________|__Withdrawal__|__£15______|__£25_______|
So far, I have this:
SELECT [Transaction ID], [Type], [Amount], (SELECT Sum([Amount]) FROM tblTransactions AS tblTransactions2 WHERE tblTransactions2.[Transaction ID] <= tblTransactions.[Transaction ID]) AS Balance
FROM tblTransactions
WHERE [Account ID]=1;
Although this does not look at the 'Type' field; it just adds the amounts; regardless of it being a deposit or withdrawal. I'm really not sure how to add this.
Thanks in advance.
Last edited: