473,388 Members | 986 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,388 software developers and data experts.

Exec stored proc from select in another stored proc

Hello everyone. I've been trying to find if this is even possible but nothing I've found has really helped.

I've got a stored proc with a few input parameters and one output parameter. I would like to call this proc from another proc and have proc 2 return the result of proc1 as a column. Some thing like this

create procedure Proc1
@Input1 numeric,
@Input2 varchar(20),
@Input3 money output
as
Select @Input3 = Amount from Table where ...
go

create procedure Proc2
@Input4 numeric,
@Input5 numeric
as
Select Column1, Column2, (exec Proc1 input1,input2, input3 output) as Column3
from table 2
where ...

Is this sort of thing even possible? Basically I need some of the results from Proc2 as inputs into Proc1 and return a single result from Proc2.

Thanks in advance.

Stephen
Dec 6 '06 #1
3 6373
iburyak
1,017 Expert 512MB
Yes it is possible but it should be not a stored procedure but a function.
Dec 6 '06 #2
iburyak
1,017 Expert 512MB
[PHP]
-- Try this
CREATE FUNCTION Proc1 (@Input1 numeric,
@Input2 varchar(20))
RETURNS VARCHAR(255)
AS
BEGIN


DECLARE @Str VARCHAR(255)

SELECT @Str = 'Your imput is : Input1 = ' + cast(@Input1 as varchar(10)) + ' Input2 = ' + @Input2

RETURN @Str
END

-- This could be executed from any stored procedure. You can pass parameters as column names
select dbo.Proc1(1, 'Hello')[/PHP]
Dec 6 '06 #3
Thanks for the quick reply. I hadn't even considered doing a function, since I have never needed one before. Well maybe I have but just found another way to do it.

Thanks again.

Stephen
Dec 6 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: June Moore | last post by:
Hi all, I have a stored procedure that return a resultset e.g. stored proc: get_employee_details select emp_id, emp_name, emp_salary, emp_position from empoloyee I would like to write...
2
by: Chip Mayan | last post by:
Hello, I am fairly new at stored procedures. I have created some that will go through a table and return a start date and an end date that is dependent upon the fiscal period you want, but I...
6
by: philipdm | last post by:
I am building a SQL statement that returns a number. when I execute the Built SQL statment EXEC(@Build). What I need to do now is take that number that comes back and store it in another variable...
2
by: hubert.trzewik | last post by:
Hello, Is it possible to EXEC stored procedure from a query? I want to execute stored procedure for every line of SELECT result table. I guess it's possible with cursors, but maybe it's...
5
by: sjoshi | last post by:
Hello I have 2 procedures setup in master database, sp_RebuildIndexesMain and sp_RebuildIndexesSub The Sub just shows and execute DBCC commands for passed database context ...
2
by: Mike Hutton | last post by:
I have a rather odd problem. I have a SP which uses temp. tables along the way, and then returns a table of results: CREATE PROCEDURE dbo.usp_myproc( @pNameList VARCHAR(6000) ) AS
6
by: David Lozzi | last post by:
Here is the proc: CREATE PROCEDURE . @CID as int, @Netname as nvarchar(25), @Return as int OUTPUT AS IF EXISTS (SELECT DISTINCT netname FROM computers WHERE CompanyID = @CID AND...
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
4
by: daz_oldham | last post by:
Hi All I am trying to execute a stored procedure that does a very simple lookup and returns a text field. However, when I try to execute it, I am getting a rather strange error that I can't seem...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.