Transfer from https://www.cnblogs.com/fengxiaojiu/p/7994124.html
The first: ROW_NUMBER () OVER () mode
select * from (
select *, ROW_NUMBER() OVER(Order by ArtistId ) AS RowId from ArtistModels
) as b
BETWEEN 10 and 20 is a RowId WHERE
--- WHERE Pages a RowId the BETWEEN -1 * article * number of pages and the number of pieces ---
The results are:
The second way: offset fetch next way (above SQL2012 version is supported: recommended)
select * from ArtistModels order by ArtistId offset 4 rows fetch next 5 rows only
--order by ArtistId offset 页数 rows fetch next 条数 rows only ----
The results are:
The third way: - top not in the way (to adapt to the 2012 version of the following database)
select top 3 * from ArtistModels
where ArtistId not in (select top 15 ArtistId from ArtistModels)
------ the WHERE Id not in ( the SELECT Top * Article number of pages the artistId from ArtistModels)
Results of the:
The fourth embodiment: paging a stored procedure
CREATE procedure page_Demo
@tablename varchar(20),
@pageSize int,
@page int
AS
declare @newspage int,
@res varchar(100)
begin
set @newspage=@pageSize*(@page - 1)
set @res='select * from ' +@tablename+ ' order by ArtistId offset '+CAST(@newspage as varchar(10)) +' rows fetch next '+ CAST(@pageSize as varchar(10)) +' rows only'
exec(@res)
end
EXEC page_Demo @tablename='ArtistModels',@pageSize=3,@page=5
Results of the:
ps: today engage in an afternoon paging through the Internet to find information and their own experiments, four page summary of ways for your reference, we can talk about a problem