Query Results By Pages

  • I would like to display query results in pages of say 20 results each.

    e.g. a table with two columns, serial# and descrition, with a few thousand entries.

    What would be the SQL query to find a specific serial number, and display all 20 results within the "page" that row happens to be in?

    e.g say serial#=3211 is in row 64, display rows 60->79.

  • Try this:

    declare @stepsize int

    declare @rownumber int

    set @step = 20

    set @rownumber = 64

    select * from table

    where rownumber between ((@rownumber / @step) * @step) and ((@rownumber / @step) * @step) + @step

    Search Books Online (BOL) for modulo

    Wilfred
    The best things in life are the simple things

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

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