CREATE PROCEDURE [dbo].[GetRecordSet]
@strSql varchar(8000),--查詢sql,如select * from [user]
@PageIndex int,--查詢當頁號
@PageSize int--每頁顯示記錄
AS
set nocount on
declare @p1 int
declare @currentPage int
set @currentPage = 0
declare @RowCount int
set @RowCount = 0
declare @PageCount int
set @PageCount = 0
exec sp_cursoropen @p1 output,@strSql,@scrollopt=1,@ccopt=1,@rowcount=@rowCount output --得到總記錄數
select @PageCount=ceiling(1.0*@rowCount/@pagesize) --得到總頁數
,@currentPage=(@PageIndex-1)*@PageSize+1
select @RowCount,@PageCount
exec sp_cursorfetch @p1,16,@currentPage,@PageSize
exec sp_cursorclose @p1
set nocount off
GO