
CREATE procedure pagination1


(@pagesize int, --页面大小,如每页存储20条记录


@pageindex int --当前页码


)


as


set nocount on


begin


declare @indextable table(id int identity(1,1),nid int) --定义表变量


declare @PageLowerBound int --定义此页的底码


declare @PageUpperBound int --定义此页的顶码


set @PageLowerBound=(@pageindex-1)*@pagesize


set @PageUpperBound=@PageLowerBound+@pagesize


set rowcount @PageUpperBound


insert into @indextable(nid) select gid from TGongwen where fariqi >dateadd(day,-365,getdate()) order by fariqi desc


select O.gid,O.mid,O.title,O.fadanwei,O.fariqi from TGongwen O,@indextable t where O.gid=t.nid


and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id


end


set nocount off