/*
名稱: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)
gokingmap 發表於2004-07-30 1:36 pm ip: 220.174.36.*
修改一點點便於其他人使用
create procedure getrecordfrompage
@tblname varchar(255), -- 表名
@fldname varchar(255), -- 欄位名
@orderfldname varchar(255), -- 排序欄位名
@statfldname varchar(255), -- 統計欄位名
@pagesize int = 10, -- 頁尺寸
@pageindex int = 1, -- 頁碼
@iscount bit = 0, -- 返回記錄總數, 非 0 值則返回
@ordertype bit = 0, -- 設定排序型別, 非 0 值則降序
@strwhere varchar(1000) = '' -- 查詢條件 (注意: 不要加 where)
as
declare @strsql varchar(6000) -- 主語句
declare @strtmp varchar(100) -- 臨時變數
declare @strorder varchar(400) -- 排序型別
if @ordertype != 0
begin
set @strtmp = "<(select min"
set @strorder = " order by [" + @orderfldname +"] desc"
end
else
begin
set @strtmp = ">(select max"
set @strorder = " order by [" + @orderfldname +"] asc"
end
set @strsql = "select top " + str(@pagesize) + " " + @fldname + " from ["
+ @tblname + "] where [" + @orderfldname + "]" + @strtmp + "(["
+ @orderfldname + "]) from (select top " + str((@pageindex-1)*@pagesize) + " ["
+ @orderfldname + "] from [" + @tblname + "]" + @strorder + ") as tbltmp)"
+ @strorder
if @strwhere != ''
set @strsql = "select top " + str(@pagesize) + " " + @fldname + " from ["
+ @tblname + "] where [" + @orderfldname + "]" + @strtmp + "(["
+ @orderfldname + "]) from (select top " + str((@pageindex-1)*@pagesize) + " ["
+ @orderfldname + "] 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) + " " + @fldname + " from ["
+ @tblname + "]" + @strtmp + " " + @strorder
end
if @iscount != 0
set @strsql = "select count(" + @statfldname + ") as total from [" + @tblname + "]"
exec (@strsql)
go
實現千萬級資料的分頁顯示
實現千萬級資料的分頁顯示 經測試,在 14483461 條記錄中查詢第 100000 頁,每頁 10 條記錄按公升序和降序第一次時間均為 0.47 秒,第二次時間均為 0.43 秒,測試語法如下 exec getrecordfrompage news,newsid,10,100000 news 為 ...
實現千萬級資料的分頁顯示
名稱 spall deletenoneunique 輸入 要查詢的表名和字段列表 輸出 呼叫 說明 實現千萬級資料的分頁顯示 可以在5秒內獲取 1448萬條記錄裡的第1200頁的100條記錄,雄不?create procedure getrecordfrompage tblname?varchar ...
實現千萬級資料的分頁顯示
create procedure dbo getrecordfrompage tblname varchar 255 表名 fldname varchar 2552 欄位名 pagesize int 10,頁尺寸 pageindex int 1,頁碼 iscount bit 0,返回記錄總數,非 0...