Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying to create list from separate Sql
Message
De
05/02/2019 10:18:26
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2016
Divers
Thread ID:
01665900
Message ID:
01665926
Vues:
46
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform