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)
 Select a subset of records

Author  Topic 

aggiekevin
Starting Member

14 Posts

Posted - 2007-09-07 : 15:36:59
I'd like to be able to pass a parameter in to a stored procedure, with which I can specify the number of rows to return.

So basically I want to do something like

create procedure sp_GetSubset (@nRows int)
as
begin
set nocount on;
select top @nRows *
from myTable
end

declare @nRows int
set @nRows = 20
exec sp_GetSubset @nRows



Unfortunately this does not work. Can anyone suggest a way I can accomplish this?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-09-07 : 15:55:19
You can use SET ROWCOUNT in SQL Server 2000. It accepts variables.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

aggiekevin
Starting Member

14 Posts

Posted - 2007-09-07 : 17:43:49
quote:
Originally posted by tkizer

You can use SET ROWCOUNT in SQL Server 2000. It accepts variables.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/



Excellent! Worked like a charm. Thanks!
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2007-09-08 : 15:22:57
select top (@nrows),...
from mytable

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -