Calculate distance between points using Long and Lat in SQL SERVER

Viewed 7636

I am using the below destination

[BMAnalytics].[dbo].[EUACTIVESTORES]

And it has columns

[Store No]
[Lat]
[Long]

Can I use these columns to self Join the [Store No] so I have each combination of Store to Store listed in two columns, called 'Source' & 'Target'

And then in a third column is it possible to calculate the distance between the two?

I have used the below previously but this only works for one single point to point,

DECLARE @source geography = 'POINT(0 51.5)'
DECLARE @target geography = 'POINT(-3 56)'

SELECT (@source.STDistance(@target))/1000

Ideally, i'd like the distance from each branch to each branch etc.

Any guidance is welcome

2 Answers
Related