最簡(jiǎn)單的SQL Server數(shù)據(jù)庫(kù)存儲(chǔ)過(guò)程分頁(yè)
1.只需要提供Sql語(yǔ)句和每頁(yè)的記錄數(shù),頁(yè)數(shù)就可以了
2,速度超快喲,100W記錄1~3秒就分出來(lái)了
3,對(duì)于存儲(chǔ)過(guò)程特別好用
--//調(diào)用的方式
表
exec up_zbh_DivPageBySql 'select * from 表',10,3
存儲(chǔ)過(guò)程
exec up_zbh_DivPageBySql 'exec 存儲(chǔ)過(guò)程',10,1
--//封裝成一個(gè)存儲(chǔ)過(guò)程,調(diào)用的時(shí)候方便的很哈!! 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 會(huì)取得Select的時(shí)候的總行數(shù)
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
