create proc Pages(@current int,@size int)
as
begin
declare @sql varchar(500)
declare @before int
set @current = @current-1
if @current<1
begin
set @current=0
end
set @before=@size*@current
set @sql='select top '+cast(@size as varchar(10))+' * from titles where title_id not in(select top '+cast(@before as varchar(10))+' title_id from titles order by pubdate) order by pubdate'
exec(@sql)
end
go
exec Pages 3,20