You can easily calculate straight line distance between two locations using SQL Server if you have latitude and longitude of both locations.
Here is a simple example:
You can also do this with single line instead of decalring variables. This way you can use this in select queries directly on multiple rows.
For more inforamtion and deep dive, visit: https://docs.microsoft.com/en-us/sql/t-sql/spatial-geography/stdistance-geography-data-type?view=sql-server-ver15
What is 4326 in the above function? It is called SRID. Ideally you shouldn’t need to change this for common uses of geography functions.
The spatial reference ID (SRID) is an identifier specifying which ellipsoidal coordinate system the geography instance is represented in. Two geography instances with different SRIDs cannot be compared.
Read more here: https://docs.microsoft.com/en-us/sql/relational-databases/spatial/create-construct-and-query-geography-instances?view=sql-server-ver16#supportedsrid