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
 General SQL Server Forums
 New to SQL Server Programming
 SELECT stored procedure results into variable

Author  Topic 

Zoroaster
Aged Yak Warrior

702 Posts

Posted - 2007-08-21 : 11:04:16
Is there a way to select the results of an SP into a variable.

For example:
DECLARE @X varchar(1000)
SELECT @X= sp_who2

How do I do this?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-21 : 11:08:28
This maybe?

create table #temp (data varchar(200))

insert #temp
exec spwho2

select @x = data from #temp


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sbalaji
Starting Member

48 Posts

Posted - 2007-08-22 : 00:28:07
In the above eg:
Number of column in the temp table should be equal to the output columns provided in the sp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-22 : 01:21:55
quote:
Originally posted by sbalaji

In the above eg:
Number of column in the temp table should be equal to the output columns provided in the sp


Yes. In addition to datatypes

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -