儲存過程分頁

2021-05-22 22:25:38 字數 1602 閱讀 8393

create database test

on primary ( name='test_data.mdf',

filename='d:/我的資料/sql/備份/test_data.mdf'

)log on

(name='test_data.ldf',

filename='d:/我的資料/sql/備份/test_data.ldf'

)if object_id('tb') is not null drop table tb

create table tb

(col int

)insert into tb select top 50 number from master..spt_values where type='p' and number>0

create proc splitpage

(@tablename nvarchar(50),

@pagesize int,--每頁顯示的數量

@currentpage int,--當前第幾頁

@pagecol nvarchar(50),--排序字段

@orderno nvarchar(50)--排序方式(desc,asc))as

/*測試用的

declare @pagecol nvarchar(50)

declare @tablename nvarchar(50)

declare @orderno nvarchar(50)

declare @pagesize int

declare @currentpage int

set @pagecol='col'

set @tablename='tb'

set @orderno='desc'

set @pagesize=10

set @currentpage=4

*/declare @sql nvarchar(1000)

set @sql=''

set @sql='

;with hgo as

(select *,row_number() over(

order by '+@pagecol+'

'+@orderno+') rank

from '+@tablename+'

)'set @sql=@sql+'select col from hgo where rank between '+ltrim((@currentpage-1)*@pagesize+1)+' and '+ltrim(@currentpage*@pagesize)

--print @sql

exec (@sql)

exec splitpage 'tb',10,1,'col','desc'

col-----------

5049

4847

4645

4443

4241

(10 行受影響)

exec splitpage 'tb',10,3,'col','desc'

col-----------

3029

2827

2625

2423

2221

(10 行受影響)

分頁儲存過程 分頁儲存過程

分頁儲存過程 alter proc dbo p pageshow pagesize int,每頁大小 currentpage int out,當前頁 housename nvarchar 50 房產名稱 totalcount int out,總記錄數 totalpage int out 總頁數 as...

分頁儲存過程

create proc p sobigo percentpage tblname varchar 255 t category 表名 strgetfields varchar 1000 需要返回的列 fldname varchar 255 排序的欄位名 pagesize int 10,頁尺寸 pag...

分頁儲存過程

create procedure pro select pageindex int,pagesize int as select student.sno,student.sname,student.s grade.math,grade.physics,grade.huaxue,grade.chine...