?
Solved

Subroutines in TSQL

Posted on 1998-07-08
2
Medium Priority
?
2,653 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
[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
2 Comments
 
LVL 7

Accepted Solution

by:
spiridonov earned 150 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.
Suggested Courses

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