Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SubProcedure (Subroutines) within Stored Procedure Expand / Collapse
Author
Message
Posted Tuesday, January 7, 2014 6:54 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 11:08 AM
Points: 91, Visits: 212
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

.....
Post #1528463
Posted Tuesday, January 7, 2014 7:08 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:55 AM
Points: 7,230, Visits: 13,709
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
Post #1528472
Posted Tuesday, January 7, 2014 8:01 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 11:08 AM
Points: 91, Visits: 212
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.
Post #1528500
Posted Tuesday, January 7, 2014 8:13 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 11:08 AM
Points: 91, Visits: 212

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.
Post #1528506
Posted Tuesday, January 7, 2014 8:17 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:55 AM
Points: 7,230, Visits: 13,709
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
Post #1528509
Posted Tuesday, January 7, 2014 11:11 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 11:08 AM
Points: 91, Visits: 212
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.
Post #1528601
Posted Tuesday, January 7, 2014 11:54 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 1:20 PM
Points: 1,090, Visits: 6,543
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
Post #1528621
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse