Solved

Subroutines in TSQL

Posted on 1998-07-08
2
2,633 Views
Last Modified: 2012-06-21
Is there a way to define a sub-routine in a stored procedure so that I could invoke it multiple times when executing my stored procedure. For example, I need to perform a set of commands several times but using different variables. I want to define this routine as a procedure with parameters and call it within my stored procedure. Creating this subroutine as a stored procedure by itself is not worth it, because it is very specific to the stored procedure I'm writing.
I looked in the TSQL manual and couldn't find any reference of defining a local procedure the way it is done in most of the languages I know.
0
Comment
Question by:mgokman
2 Comments
 
LVL 7

Accepted Solution

by:
spiridonov earned 50 total points
ID: 1091685
You can't define a subroutine in a stored procedure. The best  you can do is  create a separate stored procedure and pass parameteres to it. You can also try to use unconditional branching (GOTO). But in this case you will have to worry about returning to the right label and it is not always possible.
0
 
LVL 3

Author Comment

by:mgokman
ID: 1091686
That's what I thought.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now