User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 426,602 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,685 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 5945 | Replies: 2
Reply
Join Date: Apr 2004
Posts: 555
Reputation: Dark_Omen is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

How can I create a user defined function

  #1  
Apr 12th, 2005
Hello,

Can anyone explain to me how I can create a function that I can use in SQL.

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: Milwaukee, WI
Posts: 156
Reputation: nicentral is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
nicentral's Avatar
nicentral nicentral is offline Offline
Junior Poster

Re: How can I create a user defined function

  #2  
Apr 12th, 2005
It's pretty easy.

CREATE FUNCTION MyFunction(@variableOne datatype)
RETURNS datatype
AS
BEGIN

-- put function logic here

RETURN @variable

END

Then to call the function, you would use it in any SQL statement. For example

SELECT FIELD1, MyFunction(FIELD2) as ALIAS
FROM SOMETABLE;

Hope this helps

Andy
Nobody believes the official spokesman, but everybody trusts an unidentified source.

-- Please do not PM me with questions about a thread. If you respond to a thread, then everyone can benefit.
Reply With Quote  
Join Date: Apr 2004
Posts: 555
Reputation: Dark_Omen is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: How can I create a user defined function

  #3  
Apr 12th, 2005
Thanks, that was very helpful
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 11:18 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC