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)
 Select N records

Author  Topic 

clip
Starting Member

5 Posts

Posted - 2005-01-04 : 11:25:53
How can I select N number of records from a table

Hippi
Yak Posting Veteran

63 Posts

Posted - 2005-01-04 : 11:30:07
quote:
Originally posted by clip

How can I select N number of records from a table


Yeap,

set rowcount N
select * from table

or u can use dynamic query

HTH
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-01-06 : 06:47:30
Try this

declare @X numeric
set @x=10
print @x
exec('SELECT top '+@X+' * FROM table')

Madhivanan
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-06 : 08:09:27
if you use ser rowcount don't forget to put it back to 0 after you statement:
set rowcount N
select * from table
set rowcount 0

if you don't everything will be done for just the top N records.


Go with the flow & have fun! Else fight the flow
Go to Top of Page

clip
Starting Member

5 Posts

Posted - 2005-01-06 : 09:11:45
thanx a lot to all. The answer works very fine somehow.
cu soon...
Go to Top of Page
   

- Advertisement -