Distance between two columns (GeoLocations)

Hello - I am looking to get the distance between two columns in SQL Server.

I have 1 table only

The table has two locations stored in separate columns as Geography data types with the GeoLocation code. (E.G. 0xE6100000.......)

One location is the site, and the other is the nearest office.

Basically I want a new column to be added to the data which has the distance between both locations for all records - this will then be named [distance]

Thank You

Based on my reading of this page, looks like all you would have to do is the following:

UPDATE YourTable SET Distance = Col1.STDistance(col2);
1 Like

Thanks bud - yeah I think I did all the hard work converting them from LONG/LAT into geolocations

I did play around a bit more and managed to get it working

the only difference I used was to convert into miles
UPDATE YourTable SET Distance = Col1.STDistance(col2) / 1609.344 AS [Distance Apart];

:smile: