Row Offset in SQL Server

后端 未结 16 2377
醉酒成梦
醉酒成梦 2020-11-22 05:53

Is there any way in SQL Server to get the results starting at a given offset? For example, in another type of SQL database, it\'s possible to do:

SELECT * FR         


        
16条回答
  •  旧巷少年郎
    2020-11-22 06:11

    I would avoid using SELECT *. Specify columns you actually want even though it may be all of them.

    SQL Server 2005+

    SELECT col1, col2 
    FROM (
        SELECT col1, col2, ROW_NUMBER() OVER (ORDER BY ID) AS RowNum
        FROM MyTable
    ) AS MyDerivedTable
    WHERE MyDerivedTable.RowNum BETWEEN @startRow AND @endRow
    

    SQL Server 2000

    Efficiently Paging Through Large Result Sets in SQL Server 2000

    A More Efficient Method for Paging Through Large Result Sets

提交回复
热议问题