create procedure [storepaged]
@sql varchar(8000),
--要執行的sql語句
@page int=1,
--要顯示的頁碼
@pagesize int,
--每頁的大小
@pagecount int=0 out,
--總頁數
@recordcount int=0 out
--總記錄數
asset nocount off
if @page < 1 set @page = 1
if @pagesize < 1 set @pagesize = 5
declare @p1 int,@currentpageout int
set @currentpageout = @page
exec sp_cursoropen @p1 output,@sql,@scrollopt = 1,@ccopt = 1,@rowcount = @pagecount output
set @recordcount = @pagecount
select @pagecount=ceiling(1.0 * @pagecount/@pagesize),@page = (@page - 1) * @pagesize + 1
exec sp_cursorfetch @p1,16,@page,@pagesize
exec sp_cursorclose @p1
select @pagecount as pagecount,@recordcount as recordcount,@currentpageout as currentpage,@pagesize as pagesize
分頁儲存過程 分頁儲存過程
分頁儲存過程 alter proc dbo p pageshow pagesize int,每頁大小 currentpage int out,當前頁 housename nvarchar 50 房產名稱 totalcount int out,總記錄數 totalpage int out 總頁數 as...
SQL Server 儲存過程的分頁方案比拼
建立表 create table testtable id int identity 1,1 not null firstname nvarchar 100 collate chinese prc ci as null lastname nvarchar 100 collate chinese pr...
SQL Server 儲存過程的分頁方案比拼
建立表 create table testtable id int identity 1,1 not null firstname nvarchar 100 collate chinese prc ci as null lastname nvarchar 100 collate chinese pr...