471,854 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,854 software developers and data experts.

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 10610
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
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.