# Distance Between 2 Points of Latitude and Longitude

How can I measure the distance between 2 customers. For example, One customer is at Point A with Latitude  of 42.91 and Longitude of -77.70 and the other is at Point B with Latitude of 42.09 and Longitude of -80.12.

I am using SqlServer 2012.

The data resides in my table in the following manner:

Customer    Lat (float)    Long (float)
1                   42.91             -77.70
2                   42.09              -80.12
###### Who is Participating?

Commented:
DECLARE @a geography = geography::Point(42.91, -77.70, 4326)
DECLARE @b geography = geography::Point(42.09, -80.12, 4326)

SELECT @a.STDistance(@b)

SRID of 4326 will cause the results to be returned in meters

218773.342240962

or, in the form of a query...

select geography::Point(a.lat, a.long, 4326).STDistance(geography::Point(b.lat,b.long,4326))  from yourtable a, yourtable b
where a.customer = 1
and b.customer = 2;
0

Author Commented:
Awesome answer! And very nice job including the TSql. I am a bit of a newb and your answer was perfect!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.