-
Variables in select statement
Hi is it possible to use a variable when select the top x many records to be returned e.g.
select top @recstoreturn from orders
where @recstoreturn is passed into a stored procedure?
Cheers
Mark
-
create proc topx @recstoreturn int as
declare @query varchar(8000)
set @query = 'select top ' +convert(varchar,@recstoreturn) +'* from sysobjects'
exec (@query)
go
exec topx 5
-
Thanks, is there any way to do it without creating the text string and using the exec?
-
No. Only options are exec or sp_executesql which also requires you to build a string.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|