--以下利用PUBS库下的JOBS表进行测试
use pubs
go
select * from jobs
go
create proc proc_page
(
@PageSize int=10,--一页分几条
@CurPage int=1,--多少页
@tab varchar(22)='titles'
)
as
declare @tempA varchar(10)
declare @tempB varchar(10)
declare @tempC varchar(40)
set @tempA = Convert(varchar(10), @PageSize)
set @tempB = Convert(varchar(10),@PageSize*(@CurPage-1))
set @tempC = Convert(varchar(40),@tab)
--select @count=count(*) from @tempC where @field=@field2
--set @count = 3
exec('select top '+@tempA+' * from '+@tempC+' where job_id not in ( select top '+@tempB+' job_id from '+@tempC+') ')
go
exec proc_page 2,5,'jobs'
--以后分页只需要调用此存储过程即可...在JSP里/SERVLET里如何调用存储过程,请参见相关例子.