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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure 'TOP' Parameter

Status
Not open for further replies.

LuvASP

Programmer
May 18, 2000
46
US
Can one pass a parameter to the TOP part of the select statement through a Stored Procedure, e.g.<br><br>CREATE PROC sp_TopSelect (@sp_param int)<br>AS<br>SELECT TOP @sp_param field1,field2,fieldn<br>FROM Table....<br>----<br><br>EXEC sp_TopSelect 5<br>---- <br><br>The above example doesn't work due to a syntax error. <br>There is a solution around this but it has to be implemented in VB or VBScript (Sort the Select statement and then do a 'FOR' loop on the Recordset and make the ubound of the FOR loop dynamic). <br>I was wondering if a solution can be implemented directly into the stored procedure with the input parameter for the top part. <br><br>luvASP.&nbsp;&nbsp;
 
Nevermind... Answered my own question;<br><br>ROWCOUNT would do that. <br><br>CREATE PROC sp_TopSelect (@sp_param int)<br>AS<br>SET ROWCOUNT @sp_param<br>SELECT field1,field2,fieldn<br>FROM Table<br>ORDER BY sortfield<br>----<br><br>EXEC sp_TopSelect 5<br>---- <br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top