Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How do I get a value from an EXEC

Author  Topic 

jcmajewski
Starting Member

2 Posts

Posted - 2003-12-11 : 12:49:11
How do I get a value out of an EXEC Statement? I'm looking to put the INT that the EXEC returns into a local variable.

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2003-12-11 : 13:02:00
[code]create proc up_output
@output int output
as
set @output = 1
go

declare @out int
exec up_output @out output
select @out
go
drop proc up_output
[/code]

http://www.sqlteam.com/item.asp?ItemID=2644
Go to Top of Page

jcmajewski
Starting Member

2 Posts

Posted - 2003-12-11 : 13:17:44
I'm having trouble applying your response to my problem.

I have a select statement inside of a and exec:

EXEC ("SELECT [some_value] FROM [some_table] WHERE " + @some_conditions)

and i'm trying to get the result of that exec into another variable.

How would do that?
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2003-12-11 : 13:22:25
I am sorry. I misread your problem.

You could perform an insert into a temp table and retrieve the value from that. Variables are out of scope for Dynamic SQL though.
create table #value (some_value int)

insert into #value exec('SELECT [some_value] FROM [some_table] WHERE [some_conditions]')
select * from #value
drop table #value
Go to Top of Page
   

- Advertisement -