Can someone please confirm if this is a bug or I'm doing something wrong please?
I've this stored procedure (SQL Server 2008)
ALTER PROCEDURE [dbo].[Distance]
@origin varchar(50),@destination varchar(50),@unit varchar(5)
as
declare @or geography, @dest geography
SET @or = (select Location from [dbo].Promotion where Name=@origin )
SET @dest = (select Location from [dbo].Promotion where Name=@destination )
IF @unit='miles'
SELECT @or.STDistance(@dest)/1609.344
ELSE
--Else show the distance in km
SELECT @or.STDistance(@dest)/1000
Location is geography datatype in the database
And I've this addresses in the database
Latitude Longitude
1 -34.612654 -58.463586
2 -34.592802 -58.454317
3 -34.597889 -58.617949
Then running this:
execute dbo.Distance 'Number 1','Number 2','km'
returns 2653.49845233371 kms
execute dbo.Distance 'Number 1','Number 3','km'
returns 17.2155414117145 kms
If you go to Google Maps in the first case the are around 4 kms betweeen those coordinates and the second comparison seems to be OK.
Why the first one is so wrong? Is it a bug in SQL Server?
Thanks in advance. Guillermo.