Have a look at this setup. I am using some of the techniques from this sqlteam article: [url]http://www.sqlteam.com/item.asp?ItemID=3856[/url]I added a datetime stamp to each point trans in @abc.set nocount ondeclare @abc table (userID int, points decimal(10,2), dt datetime)insert into @abc select 9179, '3.00', getdate()- 0 union select 9179, '15.84', getdate()- 1 union select 6838, '7.92', getdate()- 2 union select 6838, '31.68', getdate()- 3 union select 6326, '19.80', getdate()- 4 union select 9530, '15.84', getdate()- 5 union select 5033, '7.92', getdate()- 6 union select 8670, '0.20', getdate()- 7 union select 8670, '4.62', getdate()- 8 union select 8670, '3.18', getdate()- 9select d.userID, d.total as 'points_used', case when d.running_total < '6.00' then running_total else '6.00' end as 'accumulated_points', case when d.running_total < '6.00' then 0 else d.running_total - '6.00' end as 'balance'from ( SELECT a.userID, a.points as 'total', SUM(b.points) as 'running_total', a.dt FROM @abc a CROSS JOIN @abc b WHERE (a.dt <= b.dt and a.userID = b.userID) GROUP BY a.userID,a.points, a.dt) dorder by d.dt desc
Nathan Skerl