Using Sum function
08:18 05 Nov 2014

I have table with following structure:

TestTable (ID INT, LoanID INT, Amount INT)

ID  LoanID  Amount
-------------------
1   1        20
2   1        30
3   1        15
4   2        40
5   2        20
6   3        50

I want to calculate LoanAmounts with this scenario:

ID  LoanID  Amount  Sum
------------------------
1   1       20      20
2   1       30      50
3   1       15      65
4   2       40      40
5   2       20      60
6   3       50      50

What is the best way to get this sum column (of course without a cursor :))

sql sql-server sql-server-2008