資料海量分頁儲存過程(3)

2021-04-17 18:24:45 字數 1400 閱讀 8983

declare @strsql   varchar(6000)       -- 主語句

declare @strtmp   varchar(1000)       -- 臨時變數

declare @strorder varchar(500)        -- 排序型別

if @ordertype != 0

begin

set @strtmp = '<(select min'

set @strorder = ' order by [' + @fldname + '] desc'

endelse

begin

set @strtmp = '>(select max'

set @strorder = ' order by [' + @fldname +'] asc'

endset @strsql = 'select top ' + str(@pagesize) + ' * from ['

+ @tblname + '] where [' + @fldname + ']' + @strtmp + '(['

+ @fldname + ']) from (select top ' + str((@pageindex-1)*@pagesize) + ' ['

+ @fldname + '] from [' + @tblname + ']' + @strorder + ') as tbltmp)'

+ @strorder

if @strwhere != ''

set @strsql = 'select top ' + str(@pagesize) + ' * from ['

+ @tblname + '] where [' + @fldname + ']' + @strtmp + '(['

+ @fldname + ']) from (select top ' + str((@pageindex-1)*@pagesize) + ' ['

+ @fldname + '] from [' + @tblname + '] where ' + @strwhere + ' '

+ @strorder + ') as tbltmp) and ' + @strwhere + ' ' + @strorder

if @pageindex = 1

begin

set @strtmp = ''

if @strwhere != ''

set @strtmp = ' where (' + @strwhere + ')'

set @strsql = 'select top ' + str(@pagesize) + ' * from ['

+ @tblname + ']' + @strtmp + ' ' + @strorder

endexec (@strsql)

go

資料海量分頁儲存過程(2)

use forepress go 物件 storedprocedure dbo usp downloaddata 指令碼日期 02 28 2008 19 06 40 set ansi nulls on goset quoted identifier on go 分頁讀取井資料儲存過程 alter p...

mysql 通用儲存過程分頁 海量資料分頁

老話題了,不多說了看 吧 測試表create table if not exists test id int 11 not null auto increment,sort int 11 title varchar 50 primary key id engine innodb default ch...

mysql 通用儲存過程分頁 海量資料分頁

測試表 create table if not exists test id int 11 not null auto increment,sort int 11 title varchar 50 primary key id engine innodb default charset gb2312...