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
 Transact-SQL (2000)
 Retrieve 10 rows at a time

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-12-26 : 10:40:22
IM writes "I want to retrieve 10 rows at a time. Can u help me out in writing a Query.

thanks,

IM"

mfemenel
Professor Frink

1421 Posts

Posted - 2002-12-26 : 10:52:35
select top 10 * from tablename

Mike
"oh, that monkey is going to pay"
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-12-26 : 11:30:38
If "10" is dynamic, you'll need to do something like this. This is best done in a stored proc, when you need to pass in the number of rows to return. TOP n is faster than this way, but TOP n isn't dynamic like this is.


DECLARE @RowCount INT

--How many rows do you want to return?
SET @ROWCOUNT = 20

--Tell SQL Server to only return the nuber of rows you specified
SET ROWCOUNT @RowCount

Select * from my table

--Un-do the change you did above. if you don't it's possible all
--your queries from here on out will return 20 rows.
SET ROWCOUNT 0



Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2002-12-27 : 05:33:12
quote:

I want to retrieve 10 rows at a time



If you mean you want to show 10 records at a time (in the application), you need to look at Paging techniques. From the front-end, if you are using ADO, you could use the Recordset.PageSize property. Or you could retreive batches of records, using an offset from the identity column.

OS

Go to Top of Page
   

- Advertisement -