hi all, I'm trying to make an SQL stored procedure in SQL Server 2000 that will perform the following:
given a specific row ID, retrieve the both the previous and next row.
the problem is that the next row may not necessarily be the correct one. The table is set up like this:
PostID (PK), BlogID (FK), Content, Published
so say I want to retrieve the adjacent entries for post ID 5, which belongs to BlogID 1. If 4 and 6 are present and belong to the same BlogID, then it would be simple to retrive PostID+1 and PostID-1. But what if post ID 4 belongs to BlogID 2, and it's say post 7 that is the correct next one to retrieve?
and this is further complicated by the fact that an entry may not be published (a draft) so I need to skip that one and get the next one that is published.
Any help is appreciated, thanks!
-SelArom
given a specific row ID, retrieve the both the previous and next row.
the problem is that the next row may not necessarily be the correct one. The table is set up like this:
PostID (PK), BlogID (FK), Content, Published
so say I want to retrieve the adjacent entries for post ID 5, which belongs to BlogID 1. If 4 and 6 are present and belong to the same BlogID, then it would be simple to retrive PostID+1 and PostID-1. But what if post ID 4 belongs to BlogID 2, and it's say post 7 that is the correct next one to retrieve?
and this is further complicated by the fact that an entry may not be published (a draft) so I need to skip that one and get the next one that is published.
Any help is appreciated, thanks!
-SelArom
