Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Top X in Stored Procedure 1

Status
Not open for further replies.

ISPrincess

Programmer
Feb 22, 2002
318
US
Is there some way to pass in the number of records to return to a stored procedure and then use that variable to return TOP X from table?
ie:

@iHowmanyrecs integer
as
Select Top @iHowManyRecs from MyTable

or will I need to build a dynamic SQL string and then exec it?


PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
You can use SET ROWCOUNT temporarily:
Code:
set rowcount @iHowmanyrecs 
select blah blah from blah blah
set rowcount 0
 
Thanks. i appreciate your quick response. I think, once again, I over-thought the issue!


PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top