亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

分頁(yè)查詢(xún) 效率最高

 更新時(shí)間:2009年06月14日 18:28:06   作者:  
給大家分享個(gè)效率最高的分頁(yè)查詢(xún) 5000萬(wàn)級(jí)別有效 比 ROWNUMBER 和Top效率高
復(fù)制代碼 代碼如下:

/*

日期:2009-03-19
功能:根據(jù)各種條件獲取 游戲國(guó)家任務(wù) 列表數(shù)據(jù)
*/
Create procedure [dbo].[PrGs_Nation_Task_GetList]

@PageSize int = 100, -- 每頁(yè)顯示記錄條數(shù),默認(rèn)為100
@PageIndex int = 1, -- 當(dāng)前提取要顯示的頁(yè)碼,默認(rèn)為1,數(shù)據(jù)庫(kù)根據(jù)PageSize,PageIndex 計(jì)算返回一頁(yè)數(shù)據(jù)

@RetTotal int output, -- 記錄總數(shù)
@RetCount int output, -- 返回記錄數(shù)
@RetPageIndex int output, -- 輸出當(dāng)前頁(yè)碼
@ReturnDesc varchar(128) output -- 返回操作結(jié)果描述
as
begin

set nocount on
set xact_abort on

set @RetTotal = 0
set @RetCount = 0
set @RetPageIndex = @PageIndex




-- 多條件取值
declare @Err int -- 錯(cuò)誤
declare @PageCount int -- 總頁(yè)數(shù)
declare @BeginRID int -- 開(kāi)始行 Rid
declare @MaxRow int -- 最后行

select @RetTotal = count(*)
from NationTask

select @Err = @@ERROR

if @Err <> 0
begin
set @ReturnDesc = '提取國(guó)家任務(wù)總數(shù)失敗!'
return -1
end

-- 如果無(wú)數(shù)據(jù), 則返回空結(jié)果集
if @RetTotal = 0
begin
set @ReturnDesc = '當(dāng)前條件無(wú)國(guó)家任務(wù)記錄!'
return 1
end

-- 計(jì)算總頁(yè)數(shù)
set @PageCount = @RetTotal / @PageSize

if @RetTotal % @PageSize > 0
begin
set @PageCount = @PageCount + 1
end

-- 超過(guò)總頁(yè)數(shù),則返回空結(jié)果集
if @PageIndex > @PageCount
begin
set @ReturnDesc = '當(dāng)前條件無(wú)國(guó)家任務(wù)記錄!'
return 1
end

-- 獲取 要返回頁(yè)面的 第一行紀(jì)錄的 Rid
set @MaxRow = @PageSize * (@PageIndex - 1) + 1

set rowcount @MaxRow

select @BeginRID = Rid
from NationTask
order by Rid desc


-- 返回?cái)?shù)據(jù)列表
set rowcount @PageSize

select Rid
,TaskName
,TaskTitle
,ImageID
,EffectID
,StartTime
from NationTask
where Rid <= @BeginRID
order by Rid desc

set @RetCount = @@rowcount

-- 結(jié)束
set @ReturnDesc = '提取國(guó)家任務(wù)列表成功!'
return 1
end

相關(guān)文章

最新評(píng)論