;WITH cte AS (
select 1 AS A union all
select 2 union ALL
select 3 union ALL
select 4 union ALL
select 5 union ALL
select 6 union ALL
select 7 union ALL
select 8 union ALL
select 9 union ALL
select 10 union ALL
select 11 union ALL
select 12 union ALL
select 13 union ALL
select 14 union ALL
select 15
),
tb1 as
(
select ROW_NUMBER() OVER(order by A) as nid, A from cte
)
select nid, A, (select sum(isnull(A,0))
from tb1 where nid <= t.nid) as [Cumulative] from tb1 as t
select 1 AS A union all
select 2 union ALL
select 3 union ALL
select 4 union ALL
select 5 union ALL
select 6 union ALL
select 7 union ALL
select 8 union ALL
select 9 union ALL
select 10 union ALL
select 11 union ALL
select 12 union ALL
select 13 union ALL
select 14 union ALL
select 15
),
tb1 as
(
select ROW_NUMBER() OVER(order by A) as nid, A from cte
)
select nid, A, (select sum(isnull(A,0))
from tb1 where nid <= t.nid) as [Cumulative] from tb1 as t