You can do this without cursorsIF there is a specific order to the records. if you can order each id by its value then you could do it.a basic example:declare @t1 table (entryId int identity(1,1), id int, val int)Insert Into @t1Select 860, 35Union Select 860, 25Union Select 860, 50Union Select 860, 50Union Select 861, 10declare @t2 table (id int, val_ttl int)Insert Into @t2Select 860, 80Union Select 861, 5Select A.entryId, A.id, A.val, val_sum = (select sum(val) From @t1 where id = A.id and entryId <= A.entryId), B.val_ttlFrom @t1 AInner Join @t2 BOn A.id = b.id--Where val_ttl > (select sum(val) From @t1 where id = A.id and entryId <= A.entryId)
Corey