加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQLServer2005 row_number() 分页存储过程

发布时间:2020-12-12 14:34:59 所属栏目:MsSql教程 来源:网络整理
导读:create procedure [dbo] . [GetProductByCategoryId] ( @CategoryID int , @PageIndex int = 0 , @PageSize int = 20 , @TotalRecords int output ) asbegin declare @ResultTable table ( RowIndex int , ProductID int , ProductName nvarchar ( 50 ), Cat
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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读