Problem with Inserting Values into a Table

  • Hi All,

    I have a Table with 3 columns

    SalesPID SalesAmount DiscountAmount

    12 120 20.00

    13 130 30.00

    14 140 40.00

    I Need An Output Table like the Following table which contains extra column with name RunningTotals which is sum of currentRow discountAmount and Previous row of RunningTotal Value.Is it Possible to fill a temporary table or tableVariable or commonTableExpressions or using any other statements without using cursor or looping statements.

    SalesPID SalesAmount DiscountAmount Running Totals

    12 120 20.00 20.00

    13 130 30.00 50.00

    14 140 40.00 90.00

    Awaiting Your Valuable Inputs

    Thanks and Best Regards,

    Rajesh

  • This is a double post... please post any replies at the following URL...

    http://www.sqlservercentral.com/Forums/Topic494354-338-1.aspx

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply