create procedure [dbo].[GetProductByCategoryId]( @CategoryID int, @PageIndex int = 0, @PageSize int = 20, @TotalRecords int output ) as begin declare @ResultTable table ( RowIndex int, ProductID int, ProductName nvarchar(50), CategoryID int, Unit nvarchar(10), UnitPrice money, Quantity int ); insert into @ResultTable select row_number() over (order by ProductID asc) as RowIndex, p.ProductID, p.ProductName, p.CategoryID, p.Unit, p.UnitPrice, p.Quantity from Products as p where CategoryID = @CategoryID; select @TotalRecords = count(*) from @ResultTable; select * from @ResultTable where RowIndex > (@PageSize * @PageIndex) and RowIndex <= (@PageSize * (@PageIndex+1)); end;
SQLServer2005 row_number() 分页存储过程
最新推荐文章于 2020-11-13 16:52:13 发布
本文介绍如何使用SQL创建存储过程,通过输入类别ID、页码和每页数量,从数据库中获取指定类别的产品信息,并进行分页展示。
1427

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



