Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Calculate distance between two points

By Scott Coleman,

The calculation of distance between two points using standard spherical geometry can be inaccurate for short distances (ten miles or less) because the sine function of very small angles approaches zero. The haversine approach ( turns this around, so it is very accurate at small distances but has larger errors (about ten miles) for points on opposite sides of the earth.

I thought this function was a great candidate for conversion to CLR, but it was actually a little slower on my test system. My theory is that the cost of marshalling the arguments outweighs any benefit of running compiled code for this function.

Total article views: 478 | Views in the last 30 days: 4
Related Articles

Calculate Distance Between Two Points

This function can be use to calculate distance between two points.


Calculate distance between 2 coordinates/latlong

This function is used to get the distance between 2 coordinates/latlong in the different formats


Calculate Distance in Miles from Latitude and Longitude

A fast and accurate way to calculate the distance in miles between two points, based on the latitude...


TSQL Challenge 34-Search for two keywords within the maximum distance

This challenge is all about searching for two keywords in a string with a maximum distance of 'one w...




sqlinsider scripts    

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones