html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

存储过程的分页!!_.NET教程_编程技术

[ ] 已经帮助:人解决问题
存储过程|分页
create proc up_GetTopicList
       @a_strForumID varchar(50) ,
       @a_intPageNo int  ,
       @a_intPageSize int
as
   /*定义局部变量*/
   declare @intBeginID         int
   declare @intEndID           int
   declare @intRootRecordCount int
   declare @intPageCount       int
   declare @intRowCount        int
   /*关闭计数*/
   set nocount on
   
  
   /*求总共根贴数*/
   select @intRootRecordCount = count(*) from bbs_topic where fatherid=0 and forumid=@a_strForumID
   if (@intRootRecordCount = 0)    --如果没有贴子,则返回零
       return 0
       
   /*判断页数是否正确*/
   if (@a_intPageNo - 1) * @a_intPageSize > @intRootRecordCount
      return (-1)

   /*求开始rootID*/
   set @intRowCount = (@a_intPageNo - 1) * @a_intPageSize + 1
   /*限制条数*/
   set rowcount @intRowCount
   select @intBeginID = rootid from bbs_topic where fatherid=0 and forumid=@a_strForumID
          order by tid desc

   /*结束rootID*/
   set @intRowCount = @a_intPageNo * @a_intPageSize
   /*限制条数*/
   set rowcount @intRowCount
   select @intEndID = rootid from bbs_topic where fatherid=0 and forumid=@a_strForumID
          order by tid desc

   /*恢复系统变量*/
   set rowcount 0
   set nocount off   

   select a.tid , a.layer , a.forumid , a.subject , a.faceid , a.hits , a.posttime , a.UserID , a.fatherid , a.rootid ,
         'Bytes' = datalength(a.content) , b.loginname  , b.Email  , b.HomePage , b.Signature , b.Point
     from bbs_topic as a join BBS_User as b on a.UserID = b.uid
     where Forumid=@a_strForumID and a.rootid between @intEndID and @intBeginID
         order by a.rootid desc , a.ordernum desc
   return(@@rowcount)
   --select @@rowcount
go    

怎么操作就不贴了!!大家好好看看,
kceHTML5中文学习网 - HTML5先行者学习网
kceHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助