CREATEprocedure main_table_pwqzc (@pagesizeint, @pageindexint, @docountbit, @this_idint) as if(@docount=1) begin selectcount(id) from luntan where this_id=@this_id end else begin declare@PageLowerBoundint declare@PageUpperBoundint set@PageLowerBound=(@pageindex-1)*@pagesize set@PageUpperBound=@PageLowerBound+@pagesize createtable #pageindex(id intidentity(1,1) notnull,nid int) setrowcount@PageUpperBound insertinto #pageindex(nid) select id from luntan where this_id=@this_idorderby reply_time desc select O.* from luntan O,#pageindex p where O.id=p.nid and p.id>@PageLowerBoundand p.id<=@PageUpperBoundorderby p.id end GO