since its already existing, what you could do is to add a trigger to do this process something likeCREATE TRIGGER SetInventoryON tablenameFOR INSERT,UPDATEASBEGINUPDATE tSET t.Inventory = t.Inventory - (t.SalesQty + COALESCE(PrevTotal,0))FROM Tablename tINNER JOIN INSERTED iON i.Store=t.StoreAND i.Item = t.ItemLEFT JOIN (SELECT Item,SUM(SalesQty) AS PrevTotal FROM Tablename t1 LEFT JOIN INSERTED i1 ON i1.Store=t1.Store AND i1.Item = t1.Item WHERE i1.Store IS NULL GROUP BY Item )pON p.Item = t.ItemEND
Also do you've any field (may id or datefield) which indicates sequence of items in this table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/