Here is my code.
Create Table [dbo].[MajorCities]
(
[CityID] int Identity(1,1),
[CityName] varchar(60),
[Latitude] float,
[Longitude] float,
GeoRef Geography
)
INSERT INTO dbo.[MajorCities] values
('New Delhi, India', 28.6, 77.2, null),
('Paris, France', 48.86667, 2.3333, null),
('Rio de Janeiro, Brazil', -22.9, -43.23333, null),
('Sydney, Australia', -33.88306, 151.21667, null),
('New York City, USA', 40.78333, -73.96667, null)
select * from [MajorCities]
UPDATE [dbo].[MajorCities]
SET [GeoRef] = geography::STPointFromText ('POINT (' + CAST ([Longitude] AS VARCHAR (20)) + ' ' +
CAST ([Latitude] AS VARCHAR (20)) + ')', 4326)
I want to find the distance between two locations in KM.
Please help me. Thanks.