Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is a User Defined Function Faster or Just Easier?

Status
Not open for further replies.

cmgaviao

Programmer
Oct 30, 2002
37
0
0
US
All,

I am converting an application which used to run all client side to process mostly within SQL Server. My question:

I have an Update that I run that Calculates the Mileage between 2 cities based on the Latitude and Longitudes of the 2 cities. The calculation is written, and my update runs fine.

I'm curious, is there any speed advantage at processing time by creating a user defined function with the formula and just passing in the 4 values to the function? Or is the only advantage to the function simplicity for the end user?

TIA,

CMG
 
As usual a function is useful if it's reused in several places in a sofware, otherwise it implies overtime to get the parameters and return the result.
If it's only used in one query for a lot of records, it's better to put before and after in your query a comment to explain it for future maintenability

-- mileage calc

(square((city1Lat-city2Lat)*(city1Lat-city2Lat)+ (city1Long-city2Long)*(city1Long-city2Long))*0.69)

-- end mileage calc

--------------------------------------------------
[highlight]Django[/highlight] [thumbsup]
bug exterminator
tips'n tricks addict
 
My formula is just as a sample, it's not the true formula !!

--------------------------------------------------
[highlight]Django[/highlight] [thumbsup]
bug exterminator
tips'n tricks addict
 
Usually a UDF is slow compared to in-line code.

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top