declare @t table ( id int, SomeNumt int ) insert into @t select 1,10 union select 2,12 union select 3,3 union select 4,15 union select 5,23
Try this:
CREATE TABLE #t( [name] varchar NULL, [val] [int] NULL, [ID] [int] NULL ) ON [PRIMARY] insert into #t (id,name,val) values (1,'A',10), (2,'B',20), (3,'C',30) select t1.id, t1.val, SUM(t2.val) as cumSum from #t t1 inner join #t t2 on t1.id >= t2.id group by t1.id, t1.val order by t1.id