Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

calling sprocs from within a sproc

Posted on 2004-10-29
6
Medium Priority
?
194 Views
Last Modified: 2008-03-06

i have a master stored procedure and i want to call other stored procedures within it.

ie something like this......

-----------------------------------------------
@parameter1,
@parameter2,
@parameter3,


exec usp_Child1 @Parameter1

exec usp_Child2 @Parameter2

exec usp_Child3 @Parameter3

-----------------------------------------------

how do i do this

thanks
0
Comment
Question by:MrKevorkian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 12444535
Just like you wrote.  You're probably asking how do you work with the returned records in the master proc?  If so, you need to make the child procs into functions or load the child proc results into temp tables.
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 12444627
yes your right each child proc will return an output value!!  it is the primary key of child1, child2, child3 etc.

------------------------------------------
@parameter1,
@parameter2,
@parameter3,
@parameter4,
@parameter5,
@parameter6

exec usp_Child1 @Parameter1, @parameter4 output
exec usp_Child2 @Parameter2, @parameter5 output
exec usp_Child3 @Parameter3, @parameter6 ouput


how do i capture the output params of these three child calls





 
0
 
LVL 21

Expert Comment

by:mastoo
ID: 12444822
If you just want the master proc to be able to work with the output parameters of the child procs, what you have should work (assuming you also declare the parameters as outputs in the child proc).   You also need to declare your variables as either parameters of the master proc or use a declare statement.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 23

Expert Comment

by:Snarf0001
ID: 12446861
The variables must be declared as output both in the called procedure and the executing statement, ie:

create proc child
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 12446870
sorry, finger slipped, a moment...
0
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 1200 total points
ID: 12446893
create proc child
  @param1 output
as
  set @param1 = 5


create proc master
as
begin

  declare @val1
  set @val1 = 2
 
  exec child @val1 output
  print @val1

end

the print statement will print 5 as assigned in proc child
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question