SQL server implements paging instance analysis and SQL instance analysis
This example describes how to implement paging on SQL server. We will share this with you for your reference. The details are as follows:
Declare @ index int, @ num intset @ index = 1 -- set @ num = 2 on the current page -- number of rows on a single page -- select top (@ num) on page 1) * from ppohdwhere doccode not in (select top (@ num * (@ index-1) doccode from ppohd order by doccode) order by doccode -- paging 2 select top (@ num) * from ppohdwhere doccode> = (select max (doccode) from (select top (@ num * (@ index-1) + 1) doccode from ppohd order by doccode) as tb) -- page 3 select top (@ num) * from (select ppohd.doc code as 'mydoccode', row_number () over (order by doccode) as sno, * from ppohd) as tbwhere tb. sno> = @ num * (@ index-1) + 1 -- paging 4 select * from (select ppohd.doc code as 'mydoccode', row_number () over (order by doccode) as sno, * from ppohd) as tbwhere tb. sno between (@ num * (@ index-1) + 1) and (@ num * @ index)