You need to write Stored Procedure like this:
USE [A_TEST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetMyData]
@count int = 0,
@current int = 0
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP(@count) *
FROM [dbo].[Table_1]
WHERE ([ID] Not IN(SELECT TOP(@current) [ID] FROM [dbo].[Table_1]))
END
Usage:
DECLARE @RC int
DECLARE @count int
DECLARE @current int
SET @count = 2
SET @current=0
EXECUTE @RC = [A_TEST].[dbo].[GetMyData]
@count ,@current
SET @count = 2
SET @current=2
EXECUTE @RC = [A_TEST].[dbo].[GetMyData]
@count ,@current
SET @count = 2
SET @current=4
EXECUTE @RC = [A_TEST].[dbo].[GetMyData]
@count ,@current
Results:
1. time (
@count=2
;
@current=0
)
1 Item 1<br />
2 Item 2<br />
2. time (
@count=2
;
@current=2
)
3 Item 3<br />
4 Item 4<br />
3. time (
@count=2
;
@current=4
)
5 Item 5<br />
6 Item 6