Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Execute a SQL string and return a value
Message
From
27/03/2001 06:07:04
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
How to Execute a SQL string and return a value
Miscellaneous
Thread ID:
00488884
Message ID:
00488884
Views:
41
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
Map
View

Click here to load this message in the networking platform