943,713 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 16270
  • MS SQL RSS
Apr 12th, 2005
0

How can I create a user defined function

Expand Post »
Hello,

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

Thanks
Similar Threads
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Apr 12th, 2005
1

Re: How can I create a user defined function

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
Reputation Points: 14
Solved Threads: 5
Junior Poster
nicentral is offline Offline
166 posts
since Apr 2005
Apr 12th, 2005
0

Re: How can I create a user defined function

Thanks, that was very helpful
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Getting current value in Select Statement
Next Thread in MS SQL Forum Timeline: Do uncompression of disk drives affects my Database?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC