• Hi

    Jeff Moden wrote a comprehensive article which covers what you want to do and investigates the various methods used

    http://www.sqlservercentral.com/articles/T-SQL/68467/

    Here's an example using the triangular join method and the quirky update method

    SELECT * INTO #MyTable

    FROM (VALUES(1,19), (2,90), (3,20), (4,8), (5, 9)) AS M(ID, VALUE)

    -- triangular join

    select ID

    , VALUE

    , (

    SELECT SUM(VALUE)

    FROM #MyTable b

    WHERE b.ID <= a.ID

    ) AS RUNNING_TOTAL

    FROM #MyTable a

    -- quirky update

    ALTER TABLE #MyTable ADD CONSTRAINT mt_pk PRIMARY KEY (ID)

    ALTER TABLE #MyTable ADD RUNNING_TOTAL INT

    ALTER TABLE #MyTable ADD RUNNING_CALC VARCHAR(100)

    DECLARE @runningTotal int = 0

    DECLARE @runningCalc varchar(100) = null

    UPDATE #MyTable

    SET @runningTotal = RUNNING_TOTAL = @runningTotal + VALUE

    ,@runningCalc = RUNNING_CALC = isnull(@runningCalc + ' + ','') + CAST(VALUE AS VARCHAR(10))

    SELECT * FROM #MyTable

    DROP TABLE #MyTable