Help with access querry

bary40

Member
Joined
Nov 9, 2003
Messages
17
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
 
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
 
Back
Top