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递归在存储过程中实现真分页
最新推荐文章于 2025-08-29 04:40:08 发布
本文详细介绍了SQL查询优化的技巧,特别是如何通过CTE(公共表表达式)实现高效分页操作,确保数据库查询性能卓越。

171

被折叠的 条评论
为什么被折叠?



