使用求出最大和最小ID进行分页

 1  一个BBS的分页:
 2 
 3  if   exists ( select   *   from  sysobjects  where  id  =   object_id ( '''' up_GetTopicList '''' ))
 4  drop   proc  up_GetTopicList
 5  go
 6 
 7  create   proc  up_GetTopicList 
 8  @a_intForumID   int  , 
 9  @a_intPageNo   int  ,
10  @a_intPageSize   int  
11  as
12  /* 定义局部变量 */
13  declare   @intBeginID   int
14  declare   @intEndID   int
15  declare   @intRootRecordCount   int
16  declare   @intPageCount   int
17  declare   @intRowCount   int
18  /* 关闭计数 */
19  set  nocount  on
20 
21  /* 检测是否有这个版面 */
22  if   not   exists ( select   *   from  forum  where  id  =   @a_intForumID )
23  return  ( - 1 )
24 
25  /* 求总共根贴数 */
26  select   @intRootRecordCount   =   count ( * from  bbs  where  fatherid = 0   and  forumid = @a_intForumID
27  if  ( @intRootRecordCount   =   0 -- 如果没有贴子,则返回零
28  return   0
29 
30  /* 判断页数是否正确 */
31  if  ( @a_intPageNo   -   1 *   @a_intPageSize   >   @intRootRecordCount
32  return  ( - 1 )
33 
34  /* 求开始rootID */
35  set   @intRowCount   =  ( @a_intPageNo   -   1 *   @a_intPageSize   +   1
36  /* 限制条数 */
37  set   rowcount   @intRowCount
38  select   @intBeginID   =  rootid  from  bbs  where  fatherid = 0   and  forumid = @a_intForumID  
39  order   by  id  desc
40 
41  /* 结束rootID */
42  set   @intRowCount   =   @a_intPageNo   *   @a_intPageSize
43  /* 限制条数 */
44  set   rowcount   @intRowCount
45  select   @intEndID   =  rootid  from  bbs  where  fatherid = 0   and  forumid = @a_intForumID  
46  order   by  id  desc
47 
48  /* 恢复系统变量 */
49  set   rowcount   0
50  set  nocount  off  
51 
52  select  a.id , a.layer , a.forumid , a.subject , a.faceid , a.hits , a.time , a.UserID , a.fatherid , 
53  a.rootid ,
54  '''' Bytes ''''   =   datalength (a.content) , b.UserName , b.Email , b.HomePage , b.Signature , b.Point
55  from  bbs  as  a  join  BBSUser  as  b  on  a.UserID  =  b.ID
56  where  Forumid = @a_intForumID   and  a.rootid  between   @intEndID   and   @intBeginID
57  order   by  a.rootid  desc  , a.ordernum  desc  
58  return ( @@rowcount )
59  -- select @@rowcount
60  go

转载于:https://www.cnblogs.com/wddavid/archive/2005/06/27/182283.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值