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)
 Load Results from SP to Variable

Author  Topic 

hismightiness
Posting Yak Master

164 Posts

Posted - 2008-08-20 : 16:56:40
How do you load a SProc result into a variable? For instance, let's say a SProc returns an Integer value. How do you load that into a local variable?

DECLARE @Var INT;
SELECT @Var = EXEC sp_ReturnAnInt32(N'input value');

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

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-20 : 17:00:57
1. Never use sp_ as a prefix for your stored procedures
2. EXEC @var = sp_ReturnAn Int32(...)
3. But better yet, use OUTPUT parameters instead of RETURN codes.



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

hismightiness
Posting Yak Master

164 Posts

Posted - 2008-08-20 : 22:14:23
Tara:
I used sp_ only for effect. I am aware of the conflicts that will possibly occur otherwise.

Thanks! This will work.

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

- Advertisement -