469,148 Members | 1,548 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,148 developers. It's quick & easy.

How to return a range of rows in sql server

Hello,

John Bell posted a reply on 2003-11-02 04:11:02 PST, that gave me an
idea how to achieve paging in sql server without row number
functionality. Thank you John. The following works for me, not very
eficient though:

SELECT * FROM
( SELECT top 5 * FROM
( SELECT top 10 * FROM
( SELECT top 10 *
FROM dft_document
ORDER BY documentkey ASC
) a
ORDER BY documentkey DESC
) b
) d
ORDER BY documentKey ASC

The innermost SELECT gives 10 rows out of which last 5 needed.

regards
Jul 20 '05 #1
2 10570
Several alternative methods described here:

www.aspfaq.com/2120

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
"Alex Ravvin" <al******@hotmail.com> wrote in message
news:f4**************************@posting.google.c om...
Hello,

John Bell posted a reply on 2003-11-02 04:11:02 PST, that gave me an
idea how to achieve paging in sql server without row number
functionality. Thank you John. The following works for me, not very
eficient though:

SELECT * FROM
( SELECT top 5 * FROM
( SELECT top 10 * FROM
( SELECT top 10 *
FROM dft_document
ORDER BY documentkey ASC
) a
ORDER BY documentkey DESC
) b
) d
ORDER BY documentKey ASC

The innermost SELECT gives 10 rows out of which last 5 needed.

regards


You can simplify this to

SELECT *
FROM (SELECT TOP 5 *
FROM (SELECT TOP 10 *
FROM dft_document
ORDER BY documentkey ASC) AS T10
ORDER BY documentkey DESC) AS T5
ORDER BY documentkey ASC

Regards,
jag
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Briniken | last post: by
7 posts views Thread by Sunny K | last post: by
4 posts views Thread by Jorey Bump | last post: by
reply views Thread by ssims | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.