how to add in column on each day to as on day...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrMob
    New Member
    • Jan 2010
    • 27

    how to add in column on each day to as on day...

    Hellow Sir,

    when i group with DATE from the Table it shows this result...

    DATE Amount

    04/01/2009 100
    04/03/2009 200
    04/04/2009 300
    04/05/2009 400
    04/06/2009 500
    04/08/2009 -700
    04/09/2009 800
    04/10/2009 1000
    04/12/2009 200
    04/13/2009 50
    04/14/2009 200
    04/15/2009 300
    04/16/2009 400
    04/17/2009 500

    BUT i need to get the Result as Below...


    DATE Amount Amount

    4/1/2009 100 100
    4/3/2009 200 300
    4/4/2009 300 600
    4/5/2009 400 1000
    4/6/2009 500 1500
    4/8/2009 -700 800
    4/9/2009 800 1600

    and so on...

    that is ... Each day the amount should be added
    for the date (04/04/2009 amount is added as 100+200+300)
    Using Cursor ..... or any kind...
    Problem..


    Thankyou....... ..
  • gpl
    New Member
    • Jul 2007
    • 152

    #2
    Realistically, you should be doing this calculation in the front-end / report code, however what you need to do is to calculate the sum of all amounts for dates that are less than - or equal to - the date of the current row.

    Something like this (not tested as I dont know your original code) - note that it will get very inefficient with increasing numbers of rows returned in the original query
    Code:
    Select [date], amount, 
    
    (Select Sum(Amount) from (your original query goes here) r where r.[date] LE s.[date]) as Running
    
    From (
    your original query goes here
    ) s

    Comment

    • MrMob
      New Member
      • Jan 2010
      • 27

      #3
      how to add in column on each day to as on day...

      Plz Sir..


      WIll you Little Elaborate more clearly with some life good Examples..
      I would be glad Enough to solve it..
      Thankyou.

      Your Disciples..

      Comment

      • gpl
        New Member
        • Jul 2007
        • 152

        #4
        If you would post the query that you developed to give you the results in your first post, I will try to give you a good example

        Comment

        Working...