分页查询 效率最高

<div class="codetitle"><a style="CURSOR: pointer" data="91587" class="copybut" id="copybut91587" onclick="doCopy('code91587')"> 代码如下:

<div class="codebody" id="code91587">
/ 日期:2009-03-19
功能:根据各种条件获取 游戏国家任务 列表数据
/
Create procedure [dbo].[PrGs_Nation_Task_GetList] @PageSize int = 100,-- 每页显示记录条数,认为100
@PageIndex int = 1,-- 当前提取显示页码认为1,数据库根据PageSize,PageIndex 计算返回一页数据 @RetTotal int output,-- 记录总数
@RetCount int output,-- 返回记录数
@RetPageIndex int output,-- 输出当前页码
@ReturnDesc varchar(128) output -- 返回操作结果描述
as
begin set nocount on
set xact_abort on set @RetTotal = 0
set @RetCount = 0
set @RetPageIndex = @PageIndex
-- 多条件取值
declare @Err int -- 错误
declare @PageCount int -- 总页数
declare @BeginRID int -- 开始行 Rid
declare @MaxRow int -- 最后行 select @RetTotal = count()
from NationTask select @Err = @@ERROR if @Err <> 0
begin
set @ReturnDesc = '提取国家任务总数失败!'
return -1
end -- 如果无数据, 则返回空结果集
if @RetTotal = 0
begin
set @ReturnDesc = '当前条件无国家任务记录!'
return 1
end -- 计算总页数
set @PageCount = @RetTotal / @PageSize if @RetTotal % @PageSize > 0
begin
set @PageCount = @PageCount + 1
end -- 超过总页数,则返回空结果集
if @PageIndex > @PageCount
begin
set @ReturnDesc = '当前条件无国家任务记录!'
return 1
end -- 获取 要返回页面的 第一行纪录的 Rid
set @MaxRow = @PageSize
(@PageIndex - 1) + 1 set rowcount @MaxRow select @BeginRID = Rid
from NationTask
order by Rid desc
-- 返回数据列表
set rowcount @PageSize select Rid
,TaskName
,TaskTitle
,ImageID
,EffectID
,StartTime
from NationTask
where Rid <= @BeginRID
order by Rid desc set @RetCount = @@rowcount -- 结束
set @ReturnDesc = '提取国家任务列表成功!'
return 1
end

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...