15,881,757 members
See more:
i have variable Table
SQL
```declare @Table Table
(
Value1 float,
Value2 float,
Total float
)
Insert into @Table values (1,1)
Insert into @Table values (2,2)
Insert into @Table values (3,3)
Insert into @Table values (4,4)
Insert into @Table values (5,5)```

i need the total column to be the sum(value1+value2) from the current row +Previous Rows

so the result 'll be like that

Value1 Values Total
---------------------
1 1 2
2 2 6
3 3 12
4 4 20
5 5 30

so how i can calculate the total
i don't want to use loop because in the real example i have about 2000 rows or more so of i use any loop statement it 'll took too much time
i need to keep the performance good

[code] block updated
Posted
Updated 10-Jul-12 18:09pm
v2

## Solution 1

Try this:
Calculating simple running totals in SQL Server[^]

Hope this helps,
Pablo.

## Solution 2

SQL
```create trigger trig_product
on table
after insert
as
declare @input varchar(25)
set @input = (select distinct    max(Total)  from  table)
update  table
set  Total = @input
from  table where ID=(select max(ID) from Table)```