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 425,885 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 2,135 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

How can I create a user defined function

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  
All times are GMT -4. The time now is 6:44 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC