Solved

subroutines in TSQL?

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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 setup several different housekeeping processes for a SQL Server.

770 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