> declare @TheOutputValue nvarchar(30) = '' > set @ThisSQL = '(Select @TheOutputValue = CAST(' + @ThisField + ' as nvarchar(30)) from ' > + @FileName + ' where ' + @KeyFieldName + ' = ' + cast(@KeyFieldValue as Varchar) + ')' > exec sp_executesql @ThisSQL, N'@ThisValue nvarchar(30) OUTPUT', @ThisValue = @ThisValue >>
>> exec sp_executesql @ThisSQL, @ThisValue out -- This works and shows result in 'results' tab >>>>The second parameter of this SP is declaration of parameters for the passed dynamic sql.
>>... >> set @ThisSQL = '(Select @TheOutptValue = CAST(' + @ThisField + ' as nvarchar(30)) from ' >> + @FileName + ' where ' + @KeyFieldName + ' = ' + cast(@KeyFieldValue as Varchar) + ')' >> >>exec sp_executesql @ThisSQL, N'@ThisValue nvarchar(30) OUTPUT', @ThisValue = @ThisValue >> >>print TheOutptValue >>... >>