分頁儲存過程

2021-09-30 02:40:32 字數 2090 閱讀 5911

/*

名稱:spall_deletenoneunique

輸入:要查詢的表名和字段列表

輸出:呼叫:

說明:實現千萬級資料的分頁顯示!--可以在5秒內獲取

1448萬條記錄裡的第1200頁的100條記錄,雄不?

create procedure getrecordfrompage

@tblname      varchar(255),       -- 表名

@fldname      varchar(255),       -- 欄位名

@pagesize     int = 10,           -- 頁尺寸

@pageindex    int = 1,            -- 頁碼

@iscount      bit = 0,            -- 返回記錄總數, 非 0 值則返回

@ordertype    bit = 0,            -- 設定排序型別, 非 0 值則降序

@strwhere     varchar(1000) = ''  -- 查詢條件 (注意: 不要加 where)

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

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

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

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

endif @iscount != 0

set @strsql = "select count(*) as total from [" + @tblname + "]"

exec (@strsql)

go

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

分頁儲存過程 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...