利用ms-sql2000的儲存過程實現資料分頁讀取,可簡化讀取的資料量。本過程的優點在於,輸入的sql語句沒有限制條件,而且寫法和思路都很簡單明瞭。
create procedure [dbo].[pageshow]
@sql varchar(8000), --where語句
@pagesize int=10, --每頁的大小(行數)
@pagecurrent int=1 --要顯示的頁
asset @sql=ltrim(rtrim(lower(@sql)))
set @sql=left(@sql,7)+' top '+cast(@pagesize*@pagecurrent as varchar(100))+' '+ right(@sql,len(@sql)-7)
set @sql='select identity(int,0,1) as pageshowid,* into #temp1 from ('+@sql+') a'
set @sql=@sql+' select * from #temp1 where pageshowid between '+cast(@pagesize*(@pagecurrent-1) as varchar(100))+' and ' +cast(@pagesize*@pagecurrent as varchar(100))
set @sql=@sql+' drop table #temp1'
exec (@sql)
go例項執行:
exec pageshow 'select * from customers where (country = '''germany''') order by customerid',10,2
exec pageshow 'select * from (select distict country from customers where (country = '''germany''') order by customerid) a',10,2
利用儲存過程分頁顯示查詢資料
原始表如下 select id,username,age from a lj 005 id username age 286李雷024 287韓梅梅327 290lili142 291lucy044 292陳吉149 293張志155 儲存過程如下 create definer root proce...
儲存過程實現分頁
一 create procedure dbo basic pagination2000 tblname varchar 255 表名 fidlelist varchar 2000 要查詢字段 fldname varchar 255 排序字段 pagesize int,頁尺寸 pageindex in...
儲存過程實現分頁
一 create procedure dbo basic pagination2000 tblname varchar 255 表名 fidlelist varchar 2000 要查詢字段 fldname varchar 255 排序字段 pagesize int,頁尺寸 pageindex in...