>Item A >Current Stock Balance : 50 > >Latest StockIn Details >InvNo ItemNo Qty Cost Date >------------------------------- >A01 ItemA 10 10 22/07/2001 - Include >A02 ItemA 10 20 21/07/2001 - Include >A03 ItemA 10 15 19/07/2001 - Include >A04 ItemA 10 10 18/07/2001 - Include >A05 ItemA 10 10 10/07/2001 - Include >A06 ItemA 10 10 08/07/2001 - Exclude since the total qty exceed 50 > >>How to use SQL to get the "included" stock in details for all of the items ??
Select distinct item, 0 from myTable into array arrQty Select * from myTable ; where Item = lcItem ; having GetQty(Item,Qty) <= lnBalance ; order by item,InvNo Function GetQty Lparameters cItem, nQty Local RowPos RowPos = asubscript(arrQty,ascan(arrQty,cItem),1) arrQty[RowPos,2]=arrQty[RowPos,2]+nQty Return arrQty[RowPos,2]Cetin