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 2005 Forums
 Transact-SQL (2005)
 HOW TO: Load a Variable from a Stored Procedure

Author  Topic 

hismightiness
Posting Yak Master

164 Posts

Posted - 2007-08-17 : 15:14:59
I have a stored procedure that will return a single result of NVARCHAR(12). I want to load that result into a variable from within another Stored Procedure. How can I do that? I have been trying variations of the following so far:

DECLARE @Variable NVARCHAR(12)
SELECT @Variable = EXEC [dbo].[spName]


Edit: By the way, the Stored Procedure being called does not accept any parameters, but it would be interesting to know how to if one needed to.

- - - -
- Will -
- - - -
http://www.strohlsitedesign.com
http://blog.strohlsitedesign.com/
http://skins.strohlsitedesign.com/

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-17 : 15:20:34
CREATE TABLE #Temp (i nvarchar(12))
insert #temp exec spname

select @variable = i from #temp



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

hismightiness
Posting Yak Master

164 Posts

Posted - 2007-08-17 : 15:31:54
That doesn't appear to be very efficient. Is that my only option?

- - - -
- Will -
- - - -
http://www.strohlsitedesign.com
http://blog.strohlsitedesign.com/
http://skins.strohlsitedesign.com/
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-08-17 : 16:48:24
I think you should be able to use an OUTPUT parameter.
Go to Top of Page
   

- Advertisement -