SQL Server 2008 paging methods?

前端 未结 7 586
傲寒
傲寒 2020-11-29 06:23

I have to work with a potentially large list of records and I\'ve been Googling for ways to avoid selecting the whole list, instead I want to let users select a page (like f

7条回答
  •  隐瞒了意图╮
    2020-11-29 06:51

    Here's an updated version of @RoadWarrior's code, using TOP. Performance is identical, and extremely fast. Make sure you have an index on TestTable.ID

    CREATE PROC dbo.PagingTest
        @SkipRows int,
        @GetRows int
    AS
    DECLARE @FirstId int
    
    SELECT   TOP (@SkipRows) 
             @FirstId = [Id]
    FROM     dbo.TestTable
    ORDER BY [Id]
    
    SELECT   TOP (@GetRows) *
    FROM     dbo.TestTable
    WHERE    [Id] >= @FirstId
    ORDER BY [Id]
    
    GO 
    

提交回复
热议问题