Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trying to create list from separate Sql
Message
From
05/02/2019 10:18:26
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2016
Miscellaneous
Thread ID:
01665900
Message ID:
01665926
Views:
45
Hi Borislav

I see where we're going with this, and now, that section looks like
  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 
It 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.
>So if you want to get value from this Dynamic SQL the you must use output parameter that can get value:
>
>
>...
> 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
>...
>
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform