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 = @ThisValueIt keeps telling me I need to declare the scalar variable "@TheOutputValue", so (obviously) there's still something I'm missing
> 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 >... >