AspNetPager分页存储过程

本文介绍了一个使用SQL创建的分页存储过程,该过程通过输入参数来控制返回的数据量及显示方式,适用于需要进行高效分页操作的应用场景。
Alter procedure adminquestion          //创建存储过程
(
@pagesize int,                               //分页大小
@pageindex int,                            //当前页数
@docount bit                                 //true:返回数据量填充分页控件,false:返回数据填充数据显示控件
)
as
set nocount on
if(@docount=1)                        //返回数据量填充分页控件
Select count(questionid) FROM question
else
begin
declare @indextable table(questionid int identity(1,1),nid int)        //定义虚拟表,包括int型的questonid字段初始值为1,自增1,已经int型的nid字段
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound                  //确定返回的数据量
insert into @indextable(nid) select questionid FROM question order by questionid desc          //定义虚拟表

select O.NodeName,0.Score,O.total,O.state ,O.questionid,O.ptime ,case when len(title)>30 then left(title,28)+'...'else title end as title  from question O,@indextable t where O.questionid=t.nid
and t.questionid>@PageLowerBound and t.questionid<=@PageUpperBound   order by t.questionid             //查找数据,返回给应用程序
end
set nocount off
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值