Hi,
I want to calculate a distance between two locations using Geograpy in SQL Server.
Thanks in advance.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Thiyagarajan EPosted Nov 22, 2016, 2:14 PM
For Ex:
CREATE PROCEDURE [dbo].[spGetNearLocations]
@latitude decimal(18,14),
@longtitude decimal(18,14)
AS
BEGIN
SET NOCOUNT ON;
-- @p1 is the point you want to calculate the distance from which is passed as parameters
declare @p1 geography = geography::Point(@latitude,@longtitude, 4326);
SELECT *
,@p1.STDistance([location_geography]) as [DistanceInKilometers]
FROM [tblLocations]
EN