--分页create table tb2
(
 id int identity(1,1) primary key,
 name varchar(10)
)insert tb2
select 'a'
union all
select 'b'
union all
select 'c'
union all
select 'd'
union all
select 'e'
union all
select 'f'
union all
select 'g'create procedure fenye(@pagesize int,@pageindex int)
as
declare @sql varchar(100)
set @sql='select top ' + cast(@pagesize as varchar(10))  + ' * from tb2 where not id in (select top ' + cast( (@pagesize*(@pageindex-1)) as varchar(10))  + ' id from tb2 order by id ) order by id'
exec(@sql)exec fenye 5,1drop procedure fenye