Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

"Beer is proof that God loves us and wants us to be happy."

-Benjamin Franklin

Posted
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

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*
Posted

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

"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
Posted
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

JvCoach23

VB.Net newbie

MS Sql Vet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...