• patrickmcginnis59 10839 (7/16/2013)


    keebler96 (7/16/2013)


    The order of the previous and the next rows should be ordered just like the SQL has inserted according to the primary keys.

    This is the problem. There is no default order by in SQL Server. You MUST order your data by the use of the order by clause. You must define the proper order for your result set.

    Just because you inserted records in a particular order does not mean that the table stores them in that order.

    From what you have provided us, you have to use Row_Number, and you have to order your composite primary key in the way you want the rows to be ordered.

    Hope that helps.

    I was able to get the previous and next rows with the SQL I posted and not use row number. I suspect the row number version would be more concise because I had to build up the comparison criteria to account for all keys.

    I was not able to get the Previous or the next row, the where condition should include all the columns.

    Cost_Center_Code,Payment_Code,Inv_No.

    Can you check your code with the updated OP code.