DECLARE @result INT ,@query NVARCHAR(MAX); SET @query = ' SET @result= 1'; EXEC sp_executesql @query, N'@result INT OUTPUT',@result = @result OUTPUT SELECT @result;