Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to store GPS co-ordinates in an MS SQL Server DB for location matching of users with GPS-enabled mobile phones.

I've read about STDistance on MSDN, but it only appears to exist in SQL Server 2008 (& later) along with the geometry and geography field types.

However, I'll need to support older versions of SQL Server as well (at least 2005).
What's the best way of storing GPS co-ordinates and calculating distances between 2 GPS locations in SQL Server 2005?

share|improve this question
up vote 4 down vote accepted

GPS co-ordinates are just latitude and longitude - if you have to support SQL 2005, then store them as numbers to your required precision.

To calculate the distance, you can implement the Haversine formula

share|improve this answer
Looking at Decimal and Numeric on MSDN and examples of GPS co-ordimnates, decimal(18,12) would be suitable? – SteB Nov 21 '12 at 9:20
Numeric is the same as decimal. It depends how precise you need to be, but it would be a good starting point. – podiluska Nov 21 '12 at 9:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.