> 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 >>
... set @ThisSQL = '(Select @ThisValue = CAST(' + @ThisField + ' as nvarchar(30)) from ' + @FileName + ' where ' + @KeyFieldName + ' = ' + cast(@KeyFieldValue as Varchar) + ')' ...