Need to sum a field in a row with same it and result needs to be cumulative in a field This is my SQL Server 2008 R2 table:

ID  Amount  date_time
001 9.00    01/01/2015 01:01:00
001 20.00   01/02/2015 01:02:00
001 20.00   01/02/2015 01:03:00 
002 20.00   01/01/2015 01:01:00
002 20.00   01/01/2015 01:02:00
003 20.00   01/02/2015 00:00:00
003 10.00   01/03/2015 00:00:00
003 5.00    01/04/2015 00:00:00


I need it to be like this with a running total (ordered by Id, and date/time):

ID  Amount  running amount    date/time
001 9.00    9.00              1/1/2015 01:01:00
001 20.00   29.00             1/2/2015 01:02:00
001 20.00   49.00             1/2/2015 01:03:00
002 20.00   20.00             1/1/2015 01:01:00
002 20.00   40.00             1/1/2015 01:02:00
003 20.00   20.00             1/2/2015 00:00:00
003 10.00   30.00             1/3/2015 00:00:00
003 5.00    35.00             1/4/2015 00:00:00
With SQL Server 2012 or newer, you can use a WINDOW function with boundaries:

SELECT *
    , SUM([Amount]) OVER(PARTITION BY [ID] ORDER BY [date_time] ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
FROM @data;


With previous version, a self JOIN can be used:

SELECT d1.ID, d1.[date_time], d1.Amount
    , SUM(d2.Amount) as running_amount
FROM @data d1
INNER JOIN @data d2 ON d1.ID = d2.ID AND d2.[date_time] &lt;= d1.[date_time]
GROUP BY d1.ID, d1.[date_time], d1.Amount;


Output:

ID  | date_time                 | Amount    | running_amount
1   | 2015-01-01 02:01:00.000   | 9         | 9
1   | 2015-01-02 02:02:00.000   | 20        | 29
1   | 2015-01-02 02:03:00.000   | 20        | 49
2   | 2015-01-01 02:01:00.000   | 20        | 20
2   | 2015-01-01 02:02:00.000   | 20        | 40
3   | 2015-01-02 01:00:00.000   | 20        | 20
3   | 2015-01-03 01:00:00.000   | 10        | 30
3   | 2015-01-04 01:00:00.000   | 5         | 35