Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Results of a query to a variable
Message
 
 
À
22/05/2003 15:27:22
John Deupree
Long Term Care Authority
Tulsa, Oklahoma, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00791809
Message ID:
00791869
Vues:
27
This message has been marked as the solution to the initial question of the thread.
You didn't assign any value to output parameter in the dynamic SQL. Try
set @sql = N'select @id = in_lname from ' + @table + ' where in_id = 7'
N'@id nvarchar(50) output' defines parameters passed into sp_executesql. @id output is actual parameter passed. They don't have to have the same name. See BOL for details.

>I don't seem to make it work. See below. What is the purpose of the output param being listed twice?
>
>Thanks
>
>
>declare @id nvarchar(50), @sql nvarchar(500), @table varchar (50)
>set @table = 'intake'
>set @sql = N'select in_lname from ' + @table + ' where in_id = 7'
>
>exec sp_executesql @sql, N'@id nvarchar(50) output', @id output
>
>if @id is null
>  print 'null'
>else
>  print @id
>
>
>Prints null every time.
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform