Skip to content

Instantly share code, notes, and snippets.

@thdotnet
Created March 9, 2020 21:38
Show Gist options
  • Save thdotnet/a70bcfa3858f6ac7f01e6990bb6bf604 to your computer and use it in GitHub Desktop.
Save thdotnet/a70bcfa3858f6ac7f01e6990bb6bf604 to your computer and use it in GitHub Desktop.
T-SQL - GeoDistance sample
DECLARE @LAT VARCHAR(10)
DECLARE @LONG VARCHAR(10)
DECLARE @GEO2 GEOGRAPHY
DECLARE @LAT_B VARCHAR(10)
DECLARE @LONG_B VARCHAR(10)
SET @LAT='29.0'
SET @LONG='-95.612528'
SET @LAT_B='32.846034'
SET @LONG_B='-96.993496'
SET @geo2= geography::Point(@LAT_B, @LONG_B, 4326)
;WITH X AS
(
SELECT geography::Point(@LAT, @LONG, 4326) A
)
SELECT
ROUND(@geo2.STDistance(A)/1000, 2) AS KM
FROM X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment