利用CTE递归在存储过程中实现真分页的技术还是比较简单的,本文我们给出了一个利用CTE递归在存储过程中实现真分页的代码示例,对于初学者来说可以套用下面的代码,代码示例如下:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER proc [dbo].[BIReport_GetAllReport_Page] @currentpage int,--当前页码 @pagesize int --每页显示的条数 as declare @beginindex int declare @endindex int begin select @beginindex=(@currentpage-1)*@pagesize select @endindex=@beginindex+@pagesize end begin With X as --CTE递归 ( Select *, row_number() over(order by ReportId) as rowNum From BIReport ) select * from X where rowNum between @beginindex+1 and @endindex end
以上就是利用CTE递归在存储过程中实现真分页的代码,希望通过阅读上面的代码,能够带给您一些收获吧。