Solved

Subroutines in TSQL

Posted on 1998-07-08
2
2,642 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
listing SQL login names of valid databases 2 20
Solar Winds can't see SQL Server Express 17 32
TSQL convert date to string 4 34
Getting invalid Syntax SQL. 3 19
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.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

856 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