You could pass your MaxRows variable into a proc and build your SQL string.
CREATE PROC sp_MyProc @AMaxRows int AS BEGIN set nocount on declare @sql varchar(255) set @sql = 'select top ' + cast(@AMaxRows) + ' * from cust' exec (@sql) END This is the only way I know of and have used. Tore? David? hope that helps anyway ----- Original Message ----- From: "Tyler Brown" <[EMAIL PROTECTED]> To: "ActiveServerPages" <[EMAIL PROTECTED]> Sent: Wednesday, August 21, 2002 12:56 AM Subject: dynamic "top *" sql statement? : is it possible to use a variable in a "top #" select statement within a : stored procedure? : : When I try declaring and using a value I get an ado error: "incorrect syntax : near [variable name]" : : How does one get around this without dynamically creating the sql string? : : --- : You are currently subscribed to activeserverpages as: [EMAIL PROTECTED] : To unsubscribe send a blank email to %%email.unsub%% : --- You are currently subscribed to activeserverpages as: [email protected] To unsubscribe send a blank email to [EMAIL PROTECTED]
