Paging SQL Server 2005 Results

前端 未结 6 2016
攒了一身酷
攒了一身酷 2020-11-28 04:53

How do I page results in SQL Server 2005?

I tried it in SQL Server 2000, but there was no reliable way to do this. I\'m now wondering if SQL Server 2005 has any buil

6条回答
  •  野性不改
    2020-11-28 05:06

    The accepted answer for this doesn't actually work for me...I had to jump through one more hoop to get it to work.

    When I tried the answer

    SELECT Row_Number() OVER(ORDER BY UserName) As RowID, UserFirstName, UserLastName
    FROM Users
    WHERE RowID Between 0 AND 9
    

    it failed, complaining that it didn't know what RowID was.

    I had to wrap it in an inner select like this:

    SELECT * 
    FROM
        (SELECT
        Row_Number() OVER(ORDER BY UserName) As RowID, UserFirstName, UserLastName
        FROM Users
        ) innerSelect
    WHERE RowID Between 0 AND 9
    

    and then it worked.

提交回复
热议问题