473,408 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to get a SP return value on another SP?

I have a SP, which will exec other SP depend on the input.
the "other SP" need to return a integer back.

How to do this?

Thanks for give me a hand.

Sep 12 '06 #1
4 9403
convert the first sp to a function that when you call it, it will
return a value.

sp can only write the value into a table and then the second sp can
pick up that value from the first sp.

Cylix wrote:
I have a SP, which will exec other SP depend on the input.
the "other SP" need to return a integer back.

How to do this?

Thanks for give me a hand.
Sep 12 '06 #2
Cylix (cy*******@gmail.com) writes:
I have a SP, which will exec other SP depend on the input.
the "other SP" need to return a integer back.

How to do this?
You could use an OUTPUT parameter for this.

CREATE PROCEDURE inner_sp @x int OUTPUT AS
SELECT @x = 23
go
CREATE PROCEDURE outer_sp AS
DECLARE @x int
EXEC inner_sp @x OUTPUT
PRINT '@x is ' + ltrim(str(@x))
The trick is that you must specify OUTPUT when you call the procedure as
well.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Sep 12 '06 #3
Thank you.

Actually, my case is a bit more complicated.
It is because, which SP is going to exec is also depends on input,
and so, in my SP, I need to
DECLARE @SQL as VARCHAR,
SET @SQL = 'exec ' + @THE_SP + ' ' + @PARM1
EXEC (@SQL)
In this structure, Can I still get the return value?
If not, any suggection?

Erland Sommarskog wrote:
You could use an OUTPUT parameter for this.

CREATE PROCEDURE inner_sp @x int OUTPUT AS
SELECT @x = 23
go
CREATE PROCEDURE outer_sp AS
DECLARE @x int
EXEC inner_sp @x OUTPUT
PRINT '@x is ' + ltrim(str(@x))

The trick is that you must specify OUTPUT when you call the procedure as
well.
Sep 12 '06 #4
Cylix (cy*******@gmail.com) writes:
Actually, my case is a bit more complicated.
It is because, which SP is going to exec is also depends on input,
and so, in my SP, I need to
DECLARE @SQL as VARCHAR,
SET @SQL = 'exec ' + @THE_SP + ' ' + @PARM1
EXEC (@SQL)
In this structure, Can I still get the return value?
If not, any suggection?
If you use sp_executesql instead of EXEC you can.

However, you don't even have to do that. You can do:

EXEC @THE_SP @PARM1 OUTPUT

That is, EXEC accepts a variable for the procedure name.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Sep 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bruce W.1 | last post by:
The intent of my web service is an RSS feed from a blog. Originally I used a StringBuilder to make the XML and returned a string from the webmethod. But this doesn't display properly in IE. So...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
5
by: Ghislain Tanguay | last post by:
Hi! I'm maybe from old school but, for me, whebn it's time to call a method from DCOM, remoting or web service returning a string or anything else I use a function. It's more verbose. In my new...
18
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
17
by: Sara | last post by:
Hi, I'm having a problem with my program and I think it stems from me not understand how to call a function and return a int value to main. What I have to do is create a program that runs...
0
by: flyingchen | last post by:
using System; using System.Windows.Forms; using System.Threading; using System.ComponentModel; namespace ProgressControl.Core { public delegate object Execute(params object args); public...
80
by: xicloid | last post by:
I'm making a function that checks the input integer and returns the value if it is a prime number. If the integer is not a prime number, then the function should return nothing. Problem is, I...
6
KoreyAusTex
by: KoreyAusTex | last post by:
If anyone can help me figure out the what the missing return statements are, I think it might be the fact that I need to add a return false in the getValue()? import java.util.*; public class...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.