SQL Server Performance

query

Discussion in 'SQL Server 2005 Reporting Services' started by jwong008, Dec 27, 2006.

  1. jwong008 New Member

    I am struggling on a query problem but it might be a piece of cake to you. Please help.

    I have a table with three columns: Year | Month | Amount.

    I would like my query to generate a result set with each row amount becomes accumulative which accumulate over years.

    For example:

    2005 | 11 | $400
    2005 | 12 | $100
    2006 | 1 | $200

    The result set should be:

    2005 | 11 | $400
    2005 | 12 | $500
    2006 | 1 | $700

    Thanks alot
  2. Madhivanan Moderator


    1 If you use Reports, you should its Running Total Feature
    2 Select Year, Month, (Select sum(amount) from table where Year<=T.year) as Amount from table
    3 Do Google search on Running total +sql server. You will find lot of links
    4 Cursor seems faster in this case. Do article search here on mmarovic also you may need to read Adam Mechanic's article

    Madhivanan

    Failing to plan is Planning to fail
  3. mmarovic Active Member

  4. Madhivanan Moderator

  5. mmarovic Active Member

    I missed it is in reporting services forum, in this case Madhivanan recommendation #1 is all you needed to know.

Share This Page