Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get var back from dynamic SQL
Message
From
07/01/2000 06:43:28
 
 
To
06/01/2000 10:56:19
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00313925
Message ID:
00314396
Views:
41
Ken,

>declare @sql varchar(128), @myvar varchar(16)

>set @sql = 'declare @myvar varchar(16) select @myvar = somefield from sometable where wherecondition'

>execute (@sql)

Can you not use a stored procedure with parameters (including an output parameter) to access the data you require?

For example

create procedure someprocedure
field varchar(20), table varchar(50), wherecondition varchar(200), myvar varchar(16) OUTPUT
as
select @myvar = @field from @table where @wherecondition

This will return the field required into the myvar variable

Cheers
Steve Lea
Previous
Reply
Map
View

Click here to load this message in the networking platform