General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
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.
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only