How do i get the previous row data in the same row in sqlserver

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phanikumar32
    New Member
    • Apr 2014
    • 22

    How do i get the previous row data in the same row in sqlserver

    Hi All,

    I want to get the previous row data in the same row with the new column name by comparing the above row data.

    Means that i have a table in sql server with 2 columns.First column name is "ItemCode" and the second column name is "Level".

    The second column has numeric data.so i want to compare the second row second column data with the first row second column data.So if the difference is "-1" then add a third column in the output. And in that(third) column i want to show the first row first column data.

    like that it will compare all the rows that are present in the table.


    I will attach the pictures also for the input and the output so that you all will understand my requirement.

    so please anyone show me how to fulfill my requirement.

    Thanks In Advance,
    Phani Kumar.
    Attached Files
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    There's no way to do it unless you have something that defines the link other than position

    Comment

    Working...