Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    88

    Unanswered: Stored Procedure running total

    What's the best way to create a field with a running total in a stored procedure:

    SELECT TestDate, ZValue,
    ZRunTot = ZValue + Last ZRunTot ????? Do I use Define + Select?
    FROM tblTest

    Thanks.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    This should work as long as TestDate values are unique:

    SELECT tblTest.TestDate,
    tblTest.ZValue,
    sum(Previous.ZValue) as ZRunTot
    FROM tblTest
    inner join tblTest Previous on Previous.TestDate <= tblTest.TestDate
    group by tblTest.TestDate, tblTest.ZValue

    blindman

  3. #3
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    88
    I'm getting some strange results ... does the tblTest file need to be sorted by the Date prior to the SELECT?

  4. #4
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    88
    Works perfectly .. thanks a bunch

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •