最簡單的SQL Server數據庫存儲過程分頁
1.只需要提供Sql語句和每頁的記錄數,頁數就可以了
2,速度超快喲,100W記錄1~3秒就分出來了
3,對于存儲過程特別好用
--//調用的方式
表
exec up_zbh_DivPageBySql 'select * from 表',10,3
存儲過程
exec up_zbh_DivPageBySql 'exec 存儲過程',10,1
--//封裝成一個存儲過程,調用的時候方便的很哈!! http://www.mypchelp.cn/
create procedure up_zbh_DivPageBySql
@strSql varchar(8000),
@nPageSize int,
@nPageCount int
as
SET NOCOUNT ON
DECLARE @P1 INT,
@nRowCount INT
--//注意:@scrollopt = 1 會取得Select的時候的總行數
EXEC sp_cursoropen @P1 OUTPUT, @strSql, @scrollopt = 2, @ccopt = 335873, @rowcount = @nRowCount OUTPUT
IF (@P1 != 0)
BEGIN
--SELECT @nRowCount AS nRecordCount, ceiling(1.0 * @nRowCount / @nPageSize) AS nPageCount, @nPageCount AS nPage
SET @nPageCount = (@nPageCount - 1) * @nPageSize + 1
EXEC sp_cursorfetch @P1, 32, @nPageCount, @nPageSize
EXEC sp_cursorclose @P1
END
GO