Home All Groups Group Topic Archive Search About

Begin Next End problems?

Author
30 Jun 2005 9:13 PM
Oded Dror
Hi there

Please take a look at this code

USE Northwind
GO
DECLARE @Index INT
SET @Index = 0
WHILE @Index <= 8
         BEGIN
   SET @Index = @Index + 1
   SELECT TOP 2 * FROM Employees
   WHERE EmployeeID = @Index
         END
GO

This will give me 1 record at the time 1
1
2
3
....
9

and this code

USE Northwind
GO
DECLARE @Index INT
SET @Index = 0
WHILE @Index <= 8
         BEGIN
   SET @Index = @Index + 1
   SELECT TOP 2 * FROM Employees
   --WHERE EmployeeID = @Index  ------------ not include this one
         END
GO

will give me 2 records at the time but
1
2

1
2
....
1
2

How do I code this to retrieve 2 records but in consecutive order like

1
2

3
4

.....

8
9

Thank you all at advance.

Oded Dror
Email: odedd***@cox.net

Author
30 Jun 2005 9:36 PM
Ravi
It looks like you are trying to do paging
If so Refer this
http://www.windowsitpro.com/Article/ArticleID/40505/40505.html?Ad=1
--
Thanks
Ravi


Show quote
"Oded Dror" wrote:

> Hi there
>
> Please take a look at this code
>
> USE Northwind
> GO
> DECLARE @Index INT
> SET @Index = 0
>  WHILE @Index <= 8
>          BEGIN
>    SET @Index = @Index + 1
>    SELECT TOP 2 * FROM Employees
>    WHERE EmployeeID = @Index
>          END
> GO
>
> This will give me 1 record at the time 1
> 1
> 2
> 3
> ....
> 9
>
> and this code
>
> USE Northwind
> GO
> DECLARE @Index INT
> SET @Index = 0
>  WHILE @Index <= 8
>          BEGIN
>    SET @Index = @Index + 1
>    SELECT TOP 2 * FROM Employees
>    --WHERE EmployeeID = @Index  ------------ not include this one
>          END
> GO
>
> will give me 2 records at the time but
> 1
> 2
>
> 1
> 2
> ....
> 1
> 2
>
> How do I code this to retrieve 2 records but in consecutive order like
>
> 1
> 2
>
> 3
> 4
>
> .....
>
> 8
> 9
>
> Thank you all at advance.
>
> Oded Dror
> Email: odedd***@cox.net
>
>
>

AddThis Social Bookmark Button