Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...