Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

subroutines in TSQL?

Posted on 2004-08-14
4
Medium Priority
?
972 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
[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
  • 3
4 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 1200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
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…

688 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