I wanted to assign value to out variable inside a dynamic query.
SET @query = 'IF EXISTS(Condition)
BEGIN
--Some action goes here
SET @result= 1
END
ELSE
BEGIN
SET @result= 2
END'
EXEC(@query)
When am trying to execute this query, I am getting an error:
Must declare the scalar variable "@result".
How can I set value to variable inside dynamic query?
Thanks in advance.