- Local time
- Today, 11:42
- Joined
- Feb 19, 2013
- Messages
- 17,391
OK try this one
Note that order is important - this is ordered earliest date to latest date and then by ID. You cannot have effectively a random order - even excel doesn't work like that.
Note if this is going into a report, you can do your running sum there
SQL:
SELECT T.ID_Invoice, T.Invoice_Date, T.Supplier, T.Payment_Term, T.Invoice_Number, T.Product, T.Quantity, T.Unit_Price, t.[Quantity]*t.[Unit_Price] AS Total, Sum([TT].[Quantity]*[TT].[Unit_Price]) AS RunTot, T.Product_Category
FROM Table_Invoice AS T INNER JOIN Table_Invoice AS TT ON T.Event = TT.Event
WHERE (((T.Event)=1) AND (([tt].[invoice_date]+([tt].[ID_Invoice]/1000))<=[t].[invoice_date]+([t].[ID_Invoice]/1000)))
GROUP BY T.ID_Invoice, T.Invoice_Date, T.Supplier, T.Payment_Term, T.Invoice_Number, T.Product, T.Quantity, T.Unit_Price, t.[Quantity]*t.[Unit_Price], T.Product_Category, T.Invoice_Date, T.ID_Invoice
ORDER BY T.Invoice_Date, T.ID_Invoice;
Note that order is important - this is ordered earliest date to latest date and then by ID. You cannot have effectively a random order - even excel doesn't work like that.
Note if this is going into a report, you can do your running sum there