Posted by Greg D. Moore \(Strider\) on 04/12/07 17:39
"pbd22" <dushkin@gmail.com> wrote in message
news:1176393322.377665.40770@y5g2000hsa.googlegroups.com...
> Hi.
>
> How does one return a range of rows.
> I know that "Top 5" will return rows 0 - 5
> but, how do I get 6 - 10?
Depends partly on which version of SQL Server you're using.
2000 or 2005?
2000, you need something like
select top 5 orderid from dbo.orders where orderid in
(select top 10 orderid from dbo.orders order by orderid) order by orderid
desc
for 2005 something like:
with OrdersCTE as
(
select row_number() over (order by orderid) as rownum, *
from dbo.orders
)
select * from OrdersCTE where rownum between 5 and 10
(obviously don't use * in your actual production code)
>
> thanks
>
--
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html
Navigation:
[Reply to this message]
|