SQL paging advice needed
OK, so saying that SQL Server isn't really my thing is kind of lame, but I'm not one to pretend I know everything. Generally I use a procedure like this to get paged data (parameters replaced with actual values for simplicity).
CREATE TABLE #PageIndex
(
idnum int IDENTITY(1, 1),
TopicID int
)
INSERT INTO #PageIndex (TopicID) SELECT TopicID FROM Topics
WHERE Topics.ForumID = 11
ORDER BY Topics.LastPostTime DESC
SELECT #PageIndex.idnum, Topics.* FROM #PageIndex JOIN Topics
ON #PageIndex.TopicID = Topics.TopicID
WHERE #PageIndex.idnum > 5000 AND #PageIndex.idnum < 5031
ORDER BY #PageIndex.idnum
This returns results quickly enough, but it seems to result in a bit of a CPU hit that I'm not entirely comfortable with. Is there a better way to go about this?