Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:33:39+00:00 2026-06-14T14:33:39+00:00

Can someone please confirm if this is a bug or I’m doing something wrong

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:33:40+00:00Added an answer on June 14, 2026 at 2:33 pm

    Ok, I’ve found what the problem is, and yes, of course it was my fault 🙂

    I’ve inserted records in the table like this

    INSERT INTO [dbo].[TestLocation]([Name],[Location],[Latitude],[Longitude]) VALUES('Location1', geography::STGeomFromText('POINT(-34.612654 -58.463586)', 4326),-34.612654,-58.463586);
    

    Then I realized that, at first, latitude and longitude were inverted, so I’ve changed then in order, but just for the last two fields and forgot to change the order in the “geography::STGeomFromText”. After running

    SELECT
      Ubicacion.Lat,
      Ubicacion.Long
    FROM
      Promotion
    

    I realized what the error was. Doh!

    Be aware of this as

    SELECT
      Ubicacion.Lat,
      Ubicacion.Long
    FROM
      Promotion
    

    Be aware of this as geography datatype is saved as binary so it is not human readable, so, unless you run the above query you won’t realize the source of the problem.

    Thanks! Guillermo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please confirm that the following is a bug with PHP 5.2.13: (thank
Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
Can someone please explain to me how this responsive approach works? This was done
Can someone please direct me on how I can add something similar to inputAccessoryView
Can someone please confirm to me that when my application is written in .NET
Can someone please help? Here is my jQuery. The scenario is this, I have
Can someone please explain why ?___SID=U is appearing in some Magento URLs on my
Can someone please explain how Read/Show works.. I cannot find any tutorials on it.
Can someone please provide an example of how to store, and read xml data
Can someone please fill in the blanks for me, including a brief description of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.