管理

一精彩的近乎完美的分页存储过程

Posted on 2009-08-30 17:06  lzhdim  阅读(534)  评论(0编辑  收藏  举报
CREATE   procedure   main_table_pwqzc  
  (@pagesize   int,  
  @pageindex   int,  
  @docount   bit,  
  @this_id   int)  
  as  
  if(@docount=1)  
  begin  
  select   count(id)   from   luntan   where   this_id=@this_id  
  end  
  else  
  begin  
  declare   @PageLowerBound   int  
  declare   @PageUpperBound   int  
  set   @PageLowerBound=(@pageindex-1)*@pagesize  
  set   @PageUpperBound=@PageLowerBound+@pagesize  
  create   table   #pageindex(id   int   identity(1,1)   not   null,nid   int)  
  set   rowcount   @PageUpperBound  
  insert   into   #pageindex(nid)  
  select   id   from   luntan   where   this_id=@this_id   order   by   reply_time   desc  
  select   O.*  
  from   luntan   O,#pageindex   p  
  where   O.id=p.nid   and   p.id>@PageLowerBound   and   p.id<=@PageUpperBound   order   by   p.id  
  end  
  GO
Copyright © 2000-2022 Lzhdim Technology Software All Rights Reserved