Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2012

    Unanswered: Select value from row above/after


    I have a table reports like the following

    Date ID Sum
    10/3/2010 1 6
    11/3/2010 1 5
    12/3/2010 1 8
    16/3/2010 1 5
    20/3/2010 1 12

    The user would select a specific date and would like to know the value in the sum field several rows before (it could be any number of rows before).
    The dates are not consecutive, as seen in the table.

    for example. I can select 16/3/2010 and 2 rows before. The return value would be 5, as this is the sum column value at date 11/3/2010.

    Any ideas?


  2. #2
    Join Date
    Nov 2003
    Provided Answers: 23
    This is easily possible with SQL Server 2012 (using the lag() or lead() function).

    Which version are you using?
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags:

    Tips for good questions:

Posting Permissions

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