Paging in SQL Server 2008, any easier?

  • Was just wondering if there was any new features that would help with paging large result sets in SQL server 2008? I hear there are lots of new features (with words such as Hierchaires being thrown about) but as of yet i have not seen anything relating to paging result sets. If so, is there any examples knocking around yet?

    /vote for LIMIT clause in SQL Server!

    Knock Knock, Who's There?, sp underscore, sp underscore who?
    spid1, spid2, spid3....

  • Paging under SQL 05 / 08 really isn't too complicated. Yes, it could be a whole lot better like the mysql limit x,y command. Here's an example:

    -- Set number of records per page

    DECLARE @RecCount int

    SET @RecCount = 20;

    -- Set Starting page number

    DECLARE @PageNum int

    SET @PageNum = 3;

    WITH RowPages AS (

    SELECT TOP( @PageNum * @RecCount )

    RowNumber = ROW_NUMBER() OVER( ORDER BY U.UserName ),

    U.*

    FROM Users U (nolock)

    )

    SELECT *

    FROM RowPages

    WHERE RowNumber > ((@PageNum - 1) * @RecCount)

    ORDER BY UserName

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply