How can I create a user defined function

Reply

Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

How can I create a user defined function

 
0
  #1
Apr 12th, 2005
Hello,

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

Thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 158
Reputation: nicentral is an unknown quantity at this point 
Solved Threads: 4
nicentral's Avatar
nicentral nicentral is offline Offline
Junior Poster

Re: How can I create a user defined function

 
1
  #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 Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: How can I create a user defined function

 
0
  #3
Apr 12th, 2005
Thanks, that was very helpful
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 10196 | Replies: 2
Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC