如何實(shí)現(xiàn)SQL Server 2000 分頁的存儲(chǔ)過程?
此文主要講述的是SQL Server 2000 分頁的存儲(chǔ)過程,以及對實(shí)現(xiàn)SQL Server 2000 分頁的存儲(chǔ)過程的實(shí)際應(yīng)用代碼的描述,以下就是具體方案的描述,希望在你今后的學(xué)習(xí)中會(huì)有所幫助。
- set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go
- set ANSI_NULLS ON
- set QUOTED_IDENTIFIER ON
- go
- /*
利用SQL未公開的存儲(chǔ)過程實(shí)現(xiàn)SQL Server 2000分頁方法簡單且效率高,已知的問題就是要多返回一個(gè)空的記錄集解決的方法是在前臺(tái)調(diào)用時(shí),用
- set recordsetrecordset=recordset.nextrecordset
的方法跳過***個(gè)記錄集此方法由J9988提供,改成了方便調(diào)用的存儲(chǔ)過程,鄒建2004.05(引用請保留此信息),缺點(diǎn)是返回2張表,***張是空表,第二張才有數(shù)據(jù)調(diào)用示例
- declare @PageCount int
- exec sp_PageView
- @sql='select * from sysobjects',
- @PageCurrent=2,
- @PageCount=@PageCount out
- SELECT @PageCount
- */
- Create PROC [dbo].[sp_PageView]
- @sql ntext,
要執(zhí)行的sql語句
@PageCurrent int=1, 要顯示的頁碼
@PageSize int=10, 每頁的大小
@PageCount int OUTPUT 總頁數(shù)
- AS
- SET NOCOUNT ON
- DECLARE @p1 int
初始化SQL Server 2000分頁游標(biāo)
- EXEC sp_cursoropen
- @cursor=@p1 OUTPUT,
- @stmt=@sql,
- @scrollopt=1,
- @ccopt=1,
- @rowcount=@PageCount OUTPUT
計(jì)算總頁數(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
c關(guān)閉SQL Server 2000分頁游標(biāo)
- EXEC sp_cursorclose @p1
以上的相關(guān)內(nèi)容就是對SQL Server 2000 分頁的存儲(chǔ)過程的介紹,望你能有所收獲。
【編輯推薦】