I took this example code from rogersaccesslibrary.com:
...and put this together this query for an invoices database I'm building:
The main difference between my SQL query and the example is that I'm trying to sum several columns in RunningSum, not just one. At first it seemed to be working, but when I tried plugging amounts into AMOUNT_PAID that were less than the AMOUNT_DUE, I noticed that RunningSum wasn't totaling correctly. (I hid PSSN_FK in these screenshots)
I'm still fairly new to Access and SQL in general. Appreciate any help. Thanks!
SQL:
SELECT tblOrderDetails.OrderDetailID,
tblOrderDetails.OrderID,
tblOrderDetails.ProductID,
tblOrderDetails.Price,
(SELECT Sum(Price) FROM tblOrderDetails as OD
WHERE OD.OrderDetailID <= tblOrderDetails.OrderDetailID
AND OD.OrderID=tblOrderDetails.OrderID) AS RunningSum
FROM tblOrderDetails;
...and put this together this query for an invoices database I'm building:
SQL:
SELECT INVOICES.INVOICE_NUM_PK,
INVOICES.PSSN_FK,
INVOICES.LIFE_AMOUNT,
INVOICES.DEPENDENT_AMOUNT,
INVOICES.DENTAL_AMOUNT,
INVOICES.SUPPLE_AMOUNT,
INVOICES.AMOUNT_PAID,
INVOICES.INVOICE_DATE,
SUM(INVOICES.LIFE_AMOUNT + INVOICES.DEPENDENT_AMOUNT + INVOICES.DENTAL_AMOUNT + INVOICES.AMOUNT_PAID) AS [Amount Due],
(SELECT SUM(INVOICES.LIFE_AMOUNT + INVOICES.DEPENDENT_AMOUNT + INVOICES.DENTAL_AMOUNT + INVOICES.AMOUNT_PAID) FROM INVOICES AS OD
WHERE OD.INVOICE_NUM_PK <= INVOICES.INVOICE_NUM_PK
AND OD.PSSN_FK = INVOICES.PSSN_FK) AS RunningSum
FROM INVOICES
GROUP BY INVOICES.INVOICE_NUM_PK, INVOICES.PSSN_FK, INVOICES.LIFE_AMOUNT, INVOICES.DEPENDENT_AMOUNT, INVOICES.DENTAL_AMOUNT, INVOICES.SUPPLE_AMOUNT, INVOICES.AMOUNT_PAID, INVOICES.INVOICE_DATE
ORDER BY INVOICES.PSSN_FK, INVOICES.INVOICE_NUM_PK;
The main difference between my SQL query and the example is that I'm trying to sum several columns in RunningSum, not just one. At first it seemed to be working, but when I tried plugging amounts into AMOUNT_PAID that were less than the AMOUNT_DUE, I noticed that RunningSum wasn't totaling correctly. (I hid PSSN_FK in these screenshots)
I'm still fairly new to Access and SQL in general. Appreciate any help. Thanks!