分页的存储过程

本文介绍了一个SQL Server中用于实现分页功能的存储过程。该存储过程通过输入当前页码和每页显示的记录数来返回指定页的数据。利用ROW_NUMBER()函数对数据进行编号,并根据页码和每页数量筛选出合适的记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分页的存储过程:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值