bary40 Posted April 14, 2006 Posted April 14, 2006 Hello I want to pass a parameter to this querry determining how many records to select parameter to replace the (Top 10 ) Select Top 10 * from customers order by id any idea will be appreciated Thanks Quote
Puiu Posted April 14, 2006 Posted April 14, 2006 You could use dynamic SQL here: declare @SQL as varchar(400) select @SQL='' select @SQL = @SQL + 'select Top ' + replace(cast(@ParamTop as varchar(10)),'''','''''') + ' * from customers' exec (@SQL) Some explaining: @ParamTop will be declared by you as a parameter for the stored procedure, type int if the id is the primary key of your table (and i think it is) than you should not use the order by id, because the results are automatically ordered by the id (Ex: select top 10 from customers) hope it helps Quote
bary40 Posted April 15, 2006 Author Posted April 15, 2006 Thanks for your reply but i need the query for access database Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.