Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
How to Execute a SQL string and return a value
I am trying to execute a SQL string, and return a value to a stored procedure. For example
Say I wanted to read @value from the calculation
'set @value= 3 + 2 '
I could use an EXEC statement to calculate the value, the statement however complains that @ value is not specified so it is specified within the sql string.
exec( 'declare @value as int set @value= 3+2 ')
The problem then is that the scope of @value is only within the SQL string. Therefore I cannot read @value.
I have also tried declaring @value from outside of the SQL string, but Query analyser complains about the syntax.
declare @value as int
exec( 'select ' @value ' = 3+2 ')
I realise that i could create a SQL command to write into a temporary table, but it feels like there should be some way to retrieve @Value.
PS. 3+2 is only an example.
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement