Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SubProcedure (Subroutines) within Stored Procedure


SubProcedure (Subroutines) within Stored Procedure

Author
Message
skb 44459
skb 44459
SSC-Enthusiastic
SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)

Group: General Forum Members
Points: 115 Visits: 267
Is it possible to write the Sub Routine inside the Stored Procedure like below ?
The reason I would like the SubRoutines is I need to use the same Variables , temp tables between these procedures.

/*Main Procedure */

SubRoutineOrders :
input parameters
output parameters

end

SubRoutineOrderLine :
input parameters
output parameters

end

SubRoutinePurchaseOrders :
input parameters
output parameters

end

SubRoutinePurchaseOrderLines :
input parameters
output parameters

end

.....
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9011 Visits: 19028
Yes you can - stored procedures with input and output parameters can be nested within a calling stored procedure. Do you really need the code blocks configured as "subroutines"?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
skb 44459
skb 44459
SSC-Enthusiastic
SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)

Group: General Forum Members
Points: 115 Visits: 267
Do you have an example ? I don't necessarily want different Stored Procedures.
I need multiple SubRoutines within One Stored Procedure, so that they can share the Variables and Temp Tables.
skb 44459
skb 44459
SSC-Enthusiastic
SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)

Group: General Forum Members
Points: 115 Visits: 267
I don't really need the code blocks configured as "subroutines". But there is no easy way to share the variables and Temp Tables between SP's.
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9011 Visits: 19028
skb 44459 (1/7/2014)
Do you have an example ? I don't necessarily want different Stored Procedures.
I need multiple SubRoutines within One Stored Procedure, so that they can share the Variables and Temp Tables.


Can you post up one such "subroutine"? It would help folks to visualise what you are trying to do.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
skb 44459
skb 44459
SSC-Enthusiastic
SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)

Group: General Forum Members
Points: 115 Visits: 267
Its not a SQL Program , it is a Progress Program.

DEFINE INPUT PARAMETER IpModule AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER IpKeyValue AS CHAR NO-UNDO.

IF IpModule = "Order" then
do :
/* Create an TempTable Record */

Run GetOrder (IpKeyValue).
end.

Procedure getOrder :
Define input parameter IpOrder as char .
/* Insert into #temp (Parent, Child, Decription) */
for each OrderLine where Order = IpOrder :
Run GetOrderLine (inpur Order, Input Line) .
end.
end procedure.

Procedure getOrderLine :
Define input parameter IpOrder as char .
Define input parameter IpLine as int .
/* Insert into #temp (Parent, Child, Decription) */
end.
end procedure.

Procedure getShipments :

Define input parameter IpOrder as char .
Define input parameter IpLine as int .
/* Insert into #temp (Parent, Child, Decription) */
end.

end procedure.

Procedure getInvoices:

Define input parameter IpOrder as char .
Define input parameter IpLine as int .
/* Insert into #temp (Parent, Child, Decription) */
end procedure.
ChrisM@home
ChrisM@home
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1161 Visits: 9736
skb 44459 (1/7/2014)
Its not a SQL Program , it is a Progress Program.

...


What make of car do you drive?


Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




Understanding and using APPLY, (I) and (II) Paul White

Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search