Click here to Skip to main content
15,913,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

Declare @sql nvarchar(max)
Declare @count int
set @count=1
set @sql='select top '+@count+' name from tbl_Test'
exec sp_executesql @sql

This Coding is working well in Sql Server.
My question is how to set that output value into one variable.
Ex: if i am using
Declare @name varchar(50)

how to set the output value into @name variable
Please need a help.

Advance Thanks,
T.Saravanan
:confused:
Posted

1 solution

You need to define an output parameter.
An example can be found here : http://www.sommarskog.se/dynamic_sql.html#sp_executesql[^]

Cheers
 
Share this answer
 
Comments
T.Saravanann 25-Aug-10 8:53am    
Reason for my vote of 5
Thanks,Its really helpful to me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900