分页的存储过程:
ALTER proc [dbo].[GetPagedProducts]
(
@pageNo int, --当前页数值,最小为,表示第一页
@pageSize int--每页显示条数
)
as
declare @itemscount int
if(@pageNo <> 1)
begin
set @itemscount=(@pageNo-1)*@pageSize+1
select Row,ProductID,ProductName,UnitPrice,SupplierID from
(select ROW_NUMBER() over(order by ProductID) as Row,ProductID,ProductName,UnitPrice,SupplierID from Products)
as productsWithRowNumbers
where Row >= @itemscount and Row <= @pageNo * @pageSize
end
else
begin
select Row,ProductID,ProductName,UnitPrice,SupplierID from
(select ROW_NUMBER() over(order by ProductID) as Row,ProductID,ProductName,UnitPrice,SupplierID from Products)
as productsWithRowNumbers
where Row >= 1 and Row <= @pageSize
end
本文介绍了一个SQL Server中用于实现分页功能的存储过程。该存储过程通过输入当前页码和每页显示的记录数来返回指定页的数据。利用ROW_NUMBER()函数对数据进行编号,并根据页码和每页数量筛选出合适的记录。
2492

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



