Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 Article Discussion
 Article: User Defined Functions

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-10-12 : 00:28:17
This article covers all the basics of User Defined Functions. It discusses how (and why) to create them and when to use them. It talks about scalar, inline table-valued and multi-statement table-valued functions.

Article Link.

Robse
Starting Member

1 Post

Posted - 2004-09-02 : 23:31:03
Nice Article! But I'm still having trouble with determining when to use a UDF...

I'm thinking that in your first example, 'USA' could return 'Unknown' ?
Seems logical ;)
Go to Top of Page

Texrat
Starting Member

1 Post

Posted - 2005-11-30 : 13:28:11
I appreciate the info, but for me a HUGE piece is missing. The article says it discusses how to create UDFs, but I don't see the part where we're told how to get those nifty functions into SQL Server. As a new SS developer that's the part I need the most and can't find anywhere.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-11-30 : 14:04:47
>>I don't see the part where we're told how to get those nifty functions into SQL Server

Did you see all the CREATE FUNCTION statements? That's how you create a function in SQL Server. If that's not what you mean, can you be more specific about what you need?
Go to Top of Page

aksam.iftikhar
Starting Member

1 Post

Posted - 2009-07-25 : 12:28:27
quote:
Originally posted by jsmith8858

>>I don't see the part where we're told how to get those nifty functions into SQL Server

>>Did you see all the CREATE FUNCTION statements? That's how you create a function in SQL Server. If that's not what you mean, can you be more specific about what you need?



>> Well, you should use SQL Query Analyzer in SQL Server 2000 to type the CREATE FUNCTION command in. Once you complete the command you can execute it by pressing F5 and you're done.

Muhammad Aksam Iftikhar
Pakistan
Go to Top of Page

praveenbattula
Starting Member

4 Posts

Posted - 2010-06-04 : 14:41:47
Here is a small example, which helps to understand it better.
T-SQL Split the giving string by delimiter and return result in a table.[url]http://praveenbattula.blogspot.com/2010/06/best-split-udf-function-with-delimeter.html[/url]

Rare Solutions
http://praveenbattula.blogspot.com
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2010-06-04 : 14:57:13
Hmmmmm....you might want to search the forum before you point people to a page entitle "Best" Split UDF function....

There are methods which do not require a loop or a temporary table. There is a whole thread devoted to the topic here.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

Jim Snyder
Starting Member

1 Post

Posted - 2015-03-24 : 10:06:01
I would have liked to see something about efficiency, or where UDFs are most useful. A UDF is serial in nature in an environment that is batch-oriented. This means if you are using a UDF to supply a column in a million row table, the UDF gets called a million times.

Due to this, the most useful way to use a UDF in a SELECT is to make it short. My favorite uses include such things as formatting dates, phones, addresses, strings etc. Long functions with complex queries are probably better to do inline.

Documentation + tidy style = maintainability
Go to Top of Page
   

- Advertisement -