Solved

subroutines in TSQL?

Posted on 2004-08-14
4
863 Views
Last Modified: 2012-06-21
Is there such a thing as subroutines in TSQL?

Or is the only way to make a separate procedure and pass values back and forth?

thanks, - brokeMyLegBiking
0
Comment
Question by:brokeMyLegBiking
  • 3
4 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 300 total points
ID: 11801540
You got it, no subroutines, no GoTo's, no extensive flow control. You can use multiple stored procedures and pass variables back and forth, but in many cases you may be better off using a non-SQL programming language. You can code whatever you need in the programming language of your choice in a DLL and install it as an Extended Stored Procedure.
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 11801569
If you want to try a DLL, here's a simple installation method from SQL Server Books Online:

How to add an extended stored procedure (Enterprise Manager)
Expand a server group, and then expand a server.
Expand Databases, and then expand the master database.
Right-click Extended Stored Procedures, and then click New Extended Stored Procedure.
In Name, enter the name of the extended stored procedure.
In Path, enter the path of the dynamic link library that contains the extended stored procedure. Optionally, click (...) to locate the DLL containing the extended stored procedure.
0
 
LVL 4

Author Comment

by:brokeMyLegBiking
ID: 11801708
ok, thanks. hm, I'll have to look into extended stored procedures. Any good resources you know of on those?
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 11801780
SQL Server books online is the first place to go for the basics on extended stored procedures, but right off you'll have to chose a programming lanuguage, and then the references for that language take over.

Create a DLL (e.g. in Visual Basic) that lets you pass in a set of variables, create code to connect to the database, pull whatever data you need, do whatever manipulations you need, and store the results in the database or pass out whatever variables you need to.

Once the DLL works in the development environment, compile it and add it to SQL Server as described above or with Query Analyzer like this:
sp_addextendedproc 'xp_hello', 'xp_hello.dll'

Then you can use your function by calling it something like this:
EXECUTE @retval = xp_hello @param1, @param2 OUTPUT
0

Featured Post

IT, Stop Being Called Into Every Meeting

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

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.
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…
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

760 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

21 Experts available now in Live!

Get 1:1 Help Now