What I want to do is to get the “value result” of the query in a variable @statement.
the code looks as follows:
declare @ID int, @name varchar (200), @statement varchar (200)
set @ID = 25
set @name = 'select FirstName + '' '' + LastName as ''Full Name''
from person.person
where BusinessEntityID = ' + cast (@ID as varchar)'
set @statement = 'My name is @name'
I'd like to show the results from @statement, and I know i should use sp_executesql to execute my @name query, and output it @statement, but I am not sure how to do that.
Any thoughts and thanks!