SQL Clone
SQLServerCentral is supported by Redgate
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 (http://en.wikipedia.org/wiki/Haversine_formula) 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: 484 | 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...


Outlier Detection with SQL Server, part 7: Cook’s Distance

By Steve Bolton[ …………I originally intended to save Cook’s and Mahalanobis Distances to close out th...


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