编辑分页的存储过程

来源:互联网 发布:物联网技术 java 编辑:程序博客网 时间:2024/05/20 13:05
 USE [BookSales]
GO
/****** 对象:  StoredProcedure [dbo].[sp_book_Select_by_Page_rowNumber]    脚本日期: 11/25/2011 21:46:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[sp_book_Select_by_Page_rowNumber]
 -- Add the parameters for the stored procedure here
 --<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,
 --<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
    @pageSize int,  --每页记录数量
 @pageCount int output,  --总页数
 @pageIndex int  --当前页索引号
AS
BEGIN
declare @totalRecords int
select @totalRecords = count(BID) from Book
if(@totalRecords % @pageSize = 0)
 set @pageCount = @totalRecords / @pageSize;
else
 set @pageCount = @totalRecords / @pageSize +1;
with temp as (select row_number() over (order by BID) as id,* from Book)
select * from temp where id between (@pageIndex -1)*@pageSize +1 and @pageIndex * @pageSize
return @totalRecords
end
原创粉丝点击