sql2005 分页存储过程
时间:2011-03-09 来源:snowolf
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: cxw
-- Create date: 2006/11/14
-- Description: 利用Row_Number函数实现分页存储过程
-- exec DividePageForROW_NUMBER 2,1,'',''
-- =============================================
Create PROCEDURE DividePageForROW_NUMBER
@iPageSize int --每页数
,@iIndexPage int --第几页
,@vOrderBy varchar(50) --排序字段
,@iRowCount int --总记录数
AS
BEGIN
SET NOCOUNT ON;
with PageTable as
(
select row_number() over(order by ReasonID) TID,* from A
)
select *
from PageTable
where TID between ((@iIndexPage-1)*@iPageSize+1) and @iPageSize*@iIndexPage
SET NOCOUNT OFF;
END
GO