1 ---------------------------------SQL2000--------------------------------
2 create procedure PageChange2005
3 (@pagesize int,
4 @pageindex int)
5 as
6 set nocount on
7 begin
8 declare @indextable table(id int identity(1,1),nid int)
9 declare @PageLowerBound int
10 declare @PageUpperBound int
11 set @PageLowerBound=(@pageindex-1)*@pagesize
12 set @PageUpperBound=@PageLowerBound+@pagesize
13 set rowcount @PageUpperBound
14 insert into @indextable(nid) select ID from TestTable order by ID desc
15 select * from TestTable O,@indextable t where O.ID=t.nid
16 and t.id between @PageLowerBound+1 and @PageUpperBound order by t.id
17 end
18 set nocount off
19 ---------------------------------SQL2005--------------------------------
20 create procedure PageChange2005
21 (@pagesize int,
22 @pageindex int)
23 as
24
25 begin
26 with temptbl as (
27 SELECT ROW_NUMBER() OVER (ORDER BY ID desc)AS Row, * from TestTable )
28 SELECT * FROM temptbl where Row between (@pageindex-1)*@pagesize+1 and (@pageindex-1)*@pagesize+@pagesize
29 end
30
2 create procedure PageChange2005
3 (@pagesize int,
4 @pageindex int)
5 as
6 set nocount on
7 begin
8 declare @indextable table(id int identity(1,1),nid int)
9 declare @PageLowerBound int
10 declare @PageUpperBound int
11 set @PageLowerBound=(@pageindex-1)*@pagesize
12 set @PageUpperBound=@PageLowerBound+@pagesize
13 set rowcount @PageUpperBound
14 insert into @indextable(nid) select ID from TestTable order by ID desc
15 select * from TestTable O,@indextable t where O.ID=t.nid
16 and t.id between @PageLowerBound+1 and @PageUpperBound order by t.id
17 end
18 set nocount off
19 ---------------------------------SQL2005--------------------------------
20 create procedure PageChange2005
21 (@pagesize int,
22 @pageindex int)
23 as
24
25 begin
26 with temptbl as (
27 SELECT ROW_NUMBER() OVER (ORDER BY ID desc)AS Row, * from TestTable )
28 SELECT * FROM temptbl where Row between (@pageindex-1)*@pagesize+1 and (@pageindex-1)*@pagesize+@pagesize
29 end
30