Solved

subroutines in TSQL?

Posted on 2004-08-14
4
892 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

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.
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

828 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