MTSkull Posted May 18, 2004 Posted May 18, 2004 Not sure where this question really fits, so I will ask it here. I have a SQL Server Stored Procedure that returns a value. How do I call that procedure from anouther stored procedure and capture the return value? Declare @MyNum bigint Exec SP_GetNextInt 'MyTable' I want to capture the return from SP_GetNextInt in @MyNum. Thanks MTS :confused: Quote "Beer is proof that God loves us and wants us to be happy." -Benjamin Franklin
Joe Mamma Posted May 18, 2004 Posted May 18, 2004 Not sure where this question really fits, so I will ask it here. I have a SQL Server Stored Procedure that returns a value. How do I call that procedure from anouther stored procedure and capture the return value? Declare @MyNum bigint Exec SP_GetNextInt 'MyTable' I want to capture the return from SP_GetNextInt in @MyNum. Thanks MTS :confused: I believe select @MyNum = SP_GetNextInt note. . . SP_ is usually not used as that reflects system level stored procedures does SP_GetNextInt return a scalar value??? consider making it a user defined function that way you can actually use it in a select statement, ie: select dbo.GetNextInt(), myField, MyOther field from myTable where [criteria here] remember that user defined functions must be prefixed by owner name Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
*Experts* Nerseus Posted May 18, 2004 *Experts* Posted May 18, 2004 Normally you'd use EXEC to call a proc and get the value back (or just call another proc in general). DECLARE @i int EXEC @i = sp_proc 'param' You might need parens, I can't remember: EXEC @i = sp_proc('param') As Joe mentioned, if you really want a prefix on your procs, I'd use something like "UP_..." instead of "SP_..." as SP is used for the system procs. Also, if the proc is simply returning a scaler and not doing any other work, I'd move it into a function. If the proc is doing multiple things, like updates or inserts and then returning the int, I'd keep it in a proc. -Nerseu Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
jvcoach23 Posted May 18, 2004 Posted May 18, 2004 sp_ is a special.. if you put that on your proc, they will run a little slower.. cause sql thinks that they are system proc.. it will end up looking in master db for them if memory servers Quote JvCoach23 VB.Net newbie MS Sql Vet
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.