Home Forums SQL Server 2008 T-SQL (SS2K8) read the current row and previous row & calculate difference reporting values over RE: read the current row and previous row & calculate difference reporting values over

  • scott_lotus (8/15/2012)


    I am trying to write a script to read the current row and previous row per device and work out the difference reporting values over X (> than 20 in example below).

    ID DEVICE VALUE

    9 456 70

    8 456 60

    7 123 70

    6 123 60

    5 456 50

    4 456 10

    3 123 50

    2 123 20

    1 123 10

    Script would return

    ID 3

    ID 5

    Large table to be queried.

    Thank you for any help.

    Scott

    There is no such thing as current row and previous row in a SQL table.

    What do you mean by current row per device? Is the one with the largest ID?

    How did you manage to calculate 3 and 5? Based on what?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]