You are here: Re: How To Return A "Range Of Rows"?? « MsSQL Server « IT news, forums, messages
Re: How To Return A "Range Of Rows"??

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация