Form Now On...

导航

 

1 分页存储过程

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

2 取出第n-m条的记录(m>n)

一般这样实现:

SELECT TOP m-n+1 *
FROM publish
WHERE (id NOT IN
    (SELECT TOP n-1 id
     FROM publish))

id 为publish 表的关键字

3 分页语句(推荐使用)

select top PageSize *

from table1

where id>

      (select max (id) from

      (select top ((PageIndex-1)*PageSize ) id from table1 order by id) as T

       )    

  order by id

posted on 2011-08-11 22:45  zjwei55  阅读(159)  评论(0编辑  收藏  举报