I have a list of purchases by date. EG:
ItemCode, Purchase Date, Purchase Qty
- XXX, 01 Jan 2012, 10
- XXX, 10 Jan 2012, 5
For the item I have a corresponding Sales transactions:
Item, Sales Date, Sales Qty
- XXX, 02 Jan 2012, -5
- XXX, 09 Jan 2012, -3
- XXX, 11 JAN 2012, -3
I am looking to get a SQL query (Without a cursor), to get the balance on each purchase order quantity. I.e Run each purchase (First in first out) to 0. (For the purposes of aging inventory )
How can you join the Purchases to the Sales to get this balance remaining each purchased Inventory Lot? Is this possible without a cursor?
Yes.
You
unionthe two tables together, and run a running total on the resulting set.To get the stock remaining at any particular time the same principal applies.
gives