If have this SQL statement:
In the first nested SELECT, I want to return all the records where lngAccountID=2 in the lngTransactionID, lngAccountID, datDate, txtType, curAmount rows. In the second nested SELECT, I use the records from the first SELECT to create a running total, for that user. I think the problem is that I am not teturing multiple rows with the first nested SELECT, as only one row is returned ffrom this statement (the values of all fields is -1). I have already made this work by using two queries:
qryTrans2A:
qryTrans2B:
But how can I analgamate the two into one query?
Thanks in advance.
Code:
SELECT (SELECT tblTransactions.lngTransactionID, tblTransactions.lngAccountID, tblTransactions.datDate, tblTransactions.txtType, tblTransactions.curAmount FROM tblTransactions WHERE tblTransactions.lngAccountID=[AccID?]) AS tblTransactionsB,
(SELECT Sum(Iif([txtType] = "Deposit", [curAmount], 0)) - Sum(Iif([txtType] = "Withdrawal", [curAmount], 0)) FROM tblTransactionsB AS tblTransactionsB2 WHERE tblTransactionsB2.[lngTransactionID] <= tblTransactionsB.[lngTransactionID]) AS Balance
FROM tblTransactions;
In the first nested SELECT, I want to return all the records where lngAccountID=2 in the lngTransactionID, lngAccountID, datDate, txtType, curAmount rows. In the second nested SELECT, I use the records from the first SELECT to create a running total, for that user. I think the problem is that I am not teturing multiple rows with the first nested SELECT, as only one row is returned ffrom this statement (the values of all fields is -1). I have already made this work by using two queries:
qryTrans2A:
Code:
SELECT tblTransactions.lngTransactionID, tblTransactions.lngAccountID, tblTransactions.datDate, tblTransactions.txtType, tblTransactions.curAmount
FROM tblTransactions
WHERE tblTransactions.lngAccountID=[AccID?];
Code:
SELECT qryTrans2A.lngTransactionID, qryTrans2A.lngAccountID, qryTrans2A.datDate, qryTrans2A.txtType, qryTrans2A.curAmount, (SELECT Sum(Iif([txtType] = "Deposit", [curAmount], 0)) - Sum(Iif([txtType] = "Withdrawal", [curAmount], 0)) FROM qryTrans2A AS qryTrans2A2 WHERE qryTrans2A2.[lngTransactionID] <= qryTrans2A.[lngTransactionID]) AS Balance
FROM qryTrans2A;
But how can I analgamate the two into one query?
Thanks in advance.
Last edited: