Create [dbo].[PageView]
@sql NVARCHAR(4000),
@CurrentPage INT,
@PageSize INT
AS
BEGIN
DECLARE @p1 INT
DECLARE @RecordCurrent INT
DECLARE @PageCount INT
DECLARE @RecordCount INT
SET NOCOUNT ON
EXEC sp_cursoropen @cursor=@p1 OUTPUT,@stmt=@sql,@scrollopt=1,@ccopt=1,@rowcount=@RecordCount OUTPUT
SET @PageCount=(@RecordCount+@PageSize-1)/@PageSize
IF ISNULL(@CurrentPage,0)<1
SET @CurrentPage=1
ELSE if ISNULL(@CurrentPage,0)>@PageCount
SET @CurrentPage=@PageCount
SELECT @CurrentPage AS CurrentPage,@RecordCount AS RecordCount,@PageSize AS PageSize,@PageCount AS PageCount
SET @RecordCurrent=(@CurrentPage-1)*@PageSize+1
EXEC sp_cursorfetch @p1,16,@RecordCurrent,@PageSize
EXEC sp_cursorclose @p1
END