For find distance between two latitude and longitude in SQL Server, we can use below mentioned query. This query calculate the distance in miles.
- DECLARE @sourceLatitude FLOAT = 28.58;
- DECLARE @sourceLongitude FLOAT = 77.329;
- DECLARE @destinationLatitude FLOAT = 27.05;
- DECLARE @destinationLongitude FLOAT = 78.001;
- DECLARE @Location FLOAT
- SET @Location = SQRT(POWER(69.1 * ( @destinationLatitude - @sourceLatitude),
- 2) + POWER(69.1 * ( @sourceLongitude
- - @destinationLongitude )
- * COS(@destinationLatitude / 57.3), 2))
- PRINT @Location

jeya deviPosted Jun 6, 2020, 9:46 AM
If i want to calculate the distance in feet what should i use ?
Mamadou DoumbiaPosted Nov 12, 2014, 3:45 AM
Hello Sir, I think you forgot the "=" sign after the "SET @location" expression. So it'll works fine. Thanks.