CREATE PROC sp_PageView
@sql ntext, --要执行的sql语句
@PageCurrent int=1, --要显示的页码
@PageSize int=10, --每页的大小
@PageCount int OUTPUT --总页数
AS
SET NOCOUNT ON
DECLARE @p1 int
--初始化分页游标
EXEC sp_cursoropen
@[email protected] OUTPUT,
@[email protected],
@scrollopt=1,
@ccopt=1,
@[email protected] OUTPUT
--计算总页数
IF ISNULL(@PageSize,0) <1
SET @PageSize=10
SET @PageCount=(@[email protected])[email protected]
IF ISNULL(@PageCurrent,0) <1 OR ISNULL(@PageCurrent,0)> @PageCount
SET @PageCurrent=1
ELSE
SET @PageCurrent=(@PageCurrent-1)[email protected]+1
--显示指定页的数据
EXEC sp_cursorfetch @p1,16,@PageCurrent,@PageSize
--关闭分页游标
EXEC sp_cursorclose @p1
GO
------解决方案--------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER procedure p_PageView
@sql ntext, --要执行的sql语句
@PageCurrent int=1, --要显示的页码
@PageSize int=10, --每页的大小
@TotalNum int OUTPUT --总行数
AS
SET NOCOUNT ON
DECLARE @p1 int,
@PageCount int
--初始化分页游标
EXEC sp_cursoropen
@[email protected] OUTPUT,
@[email protected],
@scrollopt=1,
@ccopt=1,
@[email protected] OUTPUT
--计算总页数
IF ISNULL(@PageSize,0) <1
SET @PageSize=10
SET @TotalNum=@PageCount--[email protected])-1)[email protected]
--set @PageCount=1
IF ISNULL(@PageCurrent,0) <1 OR ISNULL(@PageCurrent,0)> @PageCount
SET @PageCurrent=1
ELSE
SET @PageCurrent=(@PageCurrent-1)[email protected]+1
--显示指定页的数据
EXEC sp_cursorfetch @p1,16,@PageCurrent,@PageSize
--关闭分页游标
EXEC sp_cursorclose @p1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO