create procedure test_p @ipage int, @num int as /* @ipage 頁碼, @num 每頁的記錄數 */
begin
declare @maxpages int, @rcount int /* @maxpages 最大頁碼 */
if @ipage>=100
select @maxpages=ceiling(count(*)/@num) from test
else
select @maxpages=100000
if @ipage<=@maxpages/2
begin
select @rcount=@ipage*@num
set rowcount @rcount
select id=identity(12),name,descs,ddd into #temptable1 from test order by id
select * from #temptable1 where id>=(@ipage-1)*@num and id<= @ipage*@num
end else
begin
select @rcount=(@maxpages-@ipage+1)*@num
set rowcount @rcount
select id=identity(12),name,descs,ddd into #temptable2 from test order by id desc
select id,name, ddd,descs from #temptable2 where id>=(@maxpages-@ipage)*@num and id<= (@maxpages-@ipage+1)*@num order by id desc
endend
/********好事做到底,送個通用版吧************************************/
create procedure splitpage @qry varchar(16384),@ipage int, @num int as /*@qry sql語句, @ipage 頁數, @num 每頁記錄條數 */
begin
declare @maxpages int
declare @rcount int
declare @execsql varchar(16384)
if @ipage>=100
select @maxpages=ceiling(count(*)/@num) from test
else
select @maxpages=100000
if @ipage<=@maxpages/2
begin
select @rcount=@ipage*@num
set rowcount @rcount
set @execsql = stuff(@qry,charindex('select',@qry),6,'select sybid=identity(12),')
set @execsql = stuff(@execsql, charindex('from',@execsql),4,'into #temptable1 from')
set @execsql = @execsql || ' select * from #temptable1 where sybid>' || convert(varchar,(@ipage-1)*@num) || ' and sybid <= ' || convert(varchar,@ipage*@num)
execute (@execsql)
end else
begin
select @rcount=(@maxpages-@ipage+1)*@num
set rowcount @rcount
set @execsql = stuff(@qry,charindex('select',@qry),6,'select sybid=identity(12),')
set @execsql = stuff(@execsql, charindex('from',@execsql),4,'into #temptable1 from')
set @execsql = @execsql || ' order by sybid desc'
set @execsql = @execsql || ' select * from #temptable1 where sybid > ' || convert(varchar,(@maxpages-@ipage)*@num) || ' and sybid <= ' || convert(varchar,(@maxpages-@ipage+1)*@num)
execute (@execsql)
endend
sybase分頁儲存過程的實現
sybase分頁儲存過程應該如何實現呢?這是很多人都提到的問題,下面就為您介紹 sybase 分頁儲存過程的寫法,希望可以讓您對sybase分頁儲存過程有更多的了解。create procedure sp php page qry varchar 16384 istart int,ilimit in...
Sybase分頁顯示儲存過程
實現sybase分頁顯示儲存過程是我們經常會遇到的問題,下面就對sybase分頁顯示儲存過程的方法進行詳細介紹,供您參考。建立乙個web應用,分頁瀏覽功能必不可少。這個問題是資料庫處理中十分常見的問題。經典的資料分頁方法是 ado 紀錄集分頁法,也就是利用ado自帶的分頁功能 利用游標 來實現分頁。...
儲存過程實現分頁
一 create procedure dbo basic pagination2000 tblname varchar 255 表名 fidlelist varchar 2000 要查詢字段 fldname varchar 255 排序字段 pagesize int,頁尺寸 pageindex in...