Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How do I get records 200-210 from a query that returns 1000 records?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-19 : 08:53:04
Adrian writes "I have a query that selects all records from a table. The recordset is about 1000 records, how would I write a query to selct rows 200-210? Is there anyway that I can limit the recordset?"

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-04-19 : 09:19:08
search for "What's After Top".....should give you an appropriate solution.

Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-04-20 : 02:05:27
Andrew was referring to Article search.

Herez the actual link http://www.sqlteam.com/item.asp?ItemID=566 .




--------------------------------------------------------------


Edited by - Nazim on 04/24/2002 00:45:43
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-04-23 : 20:12:22
Adrian

Create a temp table (or a table variable table thingy) which has them in order, with a new id field. This will then have all your records with a rownumber.

eg
assuming your table has a unique column id called "id"

create table #ordered (temprownum int identity(1,1), colid int)
insert into #ordered (colid)
select id
from mytable
order by (whatever you want to order by)


then you can select whichever rows you want, eg

select b.*
from #ordered a inner join mytable b
on a.colid = b.id
where a.temprownum > 200 and a.temprownum < 210


Oh, and don't forget to
drop table #ordered

HTH

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -