CREATE PROCEDURE GetProductsPaged
@lastProductID int,
@pageSize int
AS
SET ROWCOUNT @pageSize
SELECT *
FROM Products
WHERE [standard search criteria]
AND ProductID > @lastProductID
ORDER BY [Criteria that leaves ProductID monotonically increasing]
GO
create procedure p1 @i int, @j int
as
exec ("select * from a1 as A where (select count(id) from a1 where id <= A.id)
between " +cast(@i as varchar)+" and " + cast(@j as varchar)+ " order by id")
go