• 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.