帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
存储过程分页
作者: 发布时间:2005-03-12 来源:
作者:bigeagle

if exists(select * from sysobjects where ID = object_id("up_TopicList"))
   drop proc up_TopicList
go

create proc up_TopicList
            @a_ForumID int , @a_intDays int , @a_intPageNo int , @a_intPageSize tinyint
   as
       declare @m_intRecordNumber int
       declare @m_intStartRecord  int
       select @m_intRecordNumber = @a_intPageSize * @a_intPageNo
       select @m_intStartRecord = @a_intPageSize * (@a_intPageNo - 1) + 1

       if @a_intDays = 0                      --如果不限定天数
          begin
                /*求符合条件记录数*/
                select "RecordCount" = count(*)                         
                       from BBS where Layer=1 and ForumID = @a_ForumID

               /*输出纪录*/
               /*首先定义可滚动光标*/
               set rowcount @m_intRecordNumber
               declare m_curTemp Scroll cursor
                       for
                          select a.ID ,a.Title , d.UserName , a.FaceID ,
                                'ContentSize' = datalength(a.Content) ,
                                'TotalChilds' = (select sum(TotalChilds)
                                                        from BBS as b
                                                        where a.RootID = b.RootID) ,
                                'LastReplyTime' = (select max(PostTime)
                                                          from BBS as c
                                                          where a.RootID = c.RootID)
                                from BBS as a
                                     join BBSUser as d on a.UserID = d.ID
                                where Layer=1 and ForumID = @a_ForumID
                                order by RootID desc , Layer , PostTime
               open m_curTemp
               fetch absolute @m_intStartRecord from m_curTemp
               while  @@fetch_status = 0
                      fetch next from m_curTemp

               set rowcount 0
               /*清场*/       
               CLOSE m_curTemp
               DEALLOCATE m_curTemp
          end                      
                          
       else                                --如果限定天数          

          begin
                /*求符合条件记录数*/
                select "RecordCount" = count(*)                         
                       from BBS where Layer=1 and ForumID = @a_ForumID
                                      and dateadd(day , @a_intDays , PostTime) > getdate()

               /*输出纪录*/
               /*首先定义可滚动光标*/
               set rowcount @m_intRecordNumber
               declare m_curTemp Scroll cursor
                       for
                          select a.ID ,a.Title , d.UserName , a.FaceID ,
                                'ContentSize' = datalength(a.Content) ,
                                'TotalChilds' = (select sum(TotalChilds)
                                                        from BBS as b
                                                        where a.RootID = b.RootID) ,
                                'LastReplyTime' = (select max(PostTime)
                                                          from BBS as c
                                                          where a.RootID = c.RootID)
                                from BBS as a
                                     join BBSUser as d on a.UserID = d.ID
                                where Layer=1 and ForumID = @a_ForumID
                                      and dateadd(day , @a_intDays , PostTime) > getdate()
                                order by RootID desc , Layer , PostTime
               open m_curTemp
               fetch absolute @m_intStartRecord from m_curTemp
               while  @@fetch_status = 0
                      fetch next from m_curTemp

               set rowcount 0
               /*清场*/       
               CLOSE m_curTemp
               DEALLOCATE m_curTemp
          end                                                
go

注:若在asp中调用存储过程的command对象为cm,则set rs=cm.execute,然后用set rs=rs.nextrecordset取下一条记录。
  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·存储过程对页面访问速度的影响  (2005-03-12)
 ·一段测试不用COMMAND对象来调用存  (2005-03-12)
 ·一些不长见的ASP调用存储过程的技  (2005-03-12)
 ·asp调用数据库存储过程  (2005-03-12)
 ·从文本文件中读取信息并存储入数  (2005-03-12)
 ·关于存储过程分页  (2005-03-12)
 ·把存储在SQL7的image字段的文件下  (2005-03-12)
 ·SQL2000的XML功能将现有的存储过  (2005-03-12)
 ·bbs的数据结构和存储过程(一)  (2005-03-12)
 ·bbs的数据结构和存储过程(二)  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统