?? 7.2.4 使用系統(tǒng)存儲過程實現(xiàn)的通用分頁存儲過程.sql
字號:
CREATE PROC sp_PageView
@sql ntext, --要執(zhí)行的sql語句
@PageCurrent int=1, --要顯示的頁碼
@PageSize int=10, --每頁的大小
@PageCount int OUTPUT --總頁數(shù)
AS
SET NOCOUNT ON
DECLARE @p1 int
--初始化分頁游標(biāo)
EXEC sp_cursoropen
@cursor=@p1 OUTPUT,
@stmt=@sql,
@scrollopt=1,
@ccopt=1,
@rowcount=@PageCount OUTPUT
--計算總頁數(shù)
IF ISNULL(@PageSize,0)<1
SET @PageSize=10
SET @PageCount=(@PageCount+@PageSize-1)/@PageSize
IF ISNULL(@PageCurrent,0)<1 OR ISNULL(@PageCurrent,0)>@PageCount
SET @PageCurrent=1
ELSE
SET @PageCurrent=(@PageCurrent-1)*@PageSize+1
--顯示指定頁的數(shù)據(jù)
EXEC sp_cursorfetch @p1,16,@PageCurrent,@PageSize
--關(guān)閉分頁游標(biāo)
EXEC sp_cursorclose @p1
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -