Skip to content

Instantly share code, notes, and snippets.

@65
Created March 5, 2012 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 65/1977638 to your computer and use it in GitHub Desktop.
Save 65/1977638 to your computer and use it in GitHub Desktop.
finding distance using SQL server between geocoded points
SELECT postcode, (3959*acos((sin(#latitude#/57.3) * sin(latitude/57.3))+ (cos(#latitude#/57.3) * cos(latitude/57.3) * cos((#longitude# - longitude)/57.3))))*8/5 AS exactDistance
FROM postcode
WHERE 1=1
ORDER BY (3959*acos((sin(#latitude#/57.3) * sin(latitude/57.3))+ (cos(#latitude#/57.3) * cos(latitude/57.3) * cos((#longitude# - longitude)/57.3))))*8/5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment