-- 1.T-SQL找30-40条记录,静态分页
select top 11 * from stuinfo where sid not in
(select top 29 sid from stuinfo)
--2.变量动态分页
declare @sql varchar(4000),@n int,@table varchar(20)
set @table='stuinfo'
set @n=2
set @sql='select top 5 * from '+@table+' where sid not in
(select top '+convert(varchar(20),(@n-1)*5)+' sid from '+@table+')'
select @sql
exec(@sql)
----3.存储过程分页 注意拼接时 INT 转换
alter procedure fenye
@table varchar(20), --表名
@id varchar(20), --主键
@n int=3, --查询记录
@i int=10 --一页显示10行
as
declare @sql varchar(200)
set @sql='select top '+convert(varchar(20),@i)+' * from '+@table+' where '+@id+' not in
(select top '+convert(varchar(20),(@n-1)*5)+' '+@id+' from '+@table+')'
select @sql
exec(@sql)
GO
select * from stuinfo
exec fenye stuinfo,sid,2,10
--取stuinfo表中sid主键列的, 2代表从6行记录查询,10条记录