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 in Miles from Latitude and Longitude

By RBarry Young,

With the advent of GPS and other widely available global location data, there is an increasing need to be able to accurately calculate the distance between two points over the earth's surface, from latitudes and longitudes. This SQL function does just that ,returning the distance in miles.

this function has several other advantages as well, first, it is very accurate, usually 4 to 5 decimal places. and secondly, it is much faster than most other, less accurate, algorithims. (if even more speed is needed, then include this calculation in-line in the body of your query.)

Total article views: 6714 | Views in the last 30 days: 3
Related Articles

count of rows in table is not accurate.

count of rows in table is not accurate.


How do I get accurate percentages?

Problem achieving accurate percentage figures after rounding


Searching Syscomments Accurately

As a SQL Server DBA you should know that your code is stored in syscomments by default. While most D...


Terrifyingly Accurate Technology Predictions for 2014

The end of a year is a time for reflection, but it’s also a time for running full-pelt at the new ye...


Accurate datediff by years

I tried performing datediff on two strings converted into datetimes and found that it simply subtrac...

spherical coordinates    
zip codes    

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