AspNetPager分页存储过程

来源:互联网 发布:视频剪辑软件中文版 编辑:程序博客网 时间:2024/05/16 06:56
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
 
原创粉丝点击