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 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: 6793 | 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