Solved

Subroutines in TSQL

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
monitoring configuration for SQL server DB 32 47
Table where row act as column 11 69
online  environment for testing sql queries 5 30
T-SQL to copy a database 37 66
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

749 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