944,124 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 3191
  • MS SQL RSS
May 10th, 2006
0

My zipcode query is not returning the correct results

Expand Post »
The following query:
MS SQL Syntax (Toggle Plain Text)
  1. CREATE PROCEDURE GetDistance AS
  2.  
  3. SELECT a.ZIPCODE, a.CITY, a.STATE,
  4. ROUND(
  5. (ACOS(
  6. (SIN(c.LATITUDE) * SIN(a.LATITUDE)) +
  7. (COS(c.LATITUDE) * COS(a.LATITUDE) *
  8. COS(a.LONGITUDE - c.LONGITUDE))
  9. )
  10. )
  11. * 3963,1
  12. ) AS distance
  13. FROM Zipcodes a, Zipcodes c
  14. WHERE (
  15. ACOS(
  16. (SIN(c.LATITUDE) * SIN(a.LATITUDE)) +
  17. (COS(c.LATITUDE) * COS(a.LATITUDE) * COS(a.LONGITUDE - c.LONGITUDE))
  18. )
  19. ) * 3963 <= '10'
  20. AND c.ZIPCODE='80222'
  21. ORDER BY distance
  22. GO
tells me that the only zipcode within 10 miles of 80222 is 80222 and if I replace 10 with 25 it offers only one additional zip code? Does anyone have any ideas why this might be happening?
Thanks so much for any suggestions anyone has to offer.:rolleyes:
Last edited by cscgal; May 11th, 2006 at 4:09 pm. Reason: Added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reessee is offline Offline
3 posts
since May 2006
May 10th, 2006
0

Re: My zipcode query is not returning the correct results

give us table setup and what data you have in those tables
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
May 10th, 2006
0

Re: My zipcode query is not returning the correct results

Column Name Data Type
ZIPCODE nvarchar
LATITUDE float
LONGITUDE float
CITY nvarchar
STATE nvarchar
ABBR nvarchar

The first five entries look like this:
00501 40.81718 -73.04536 HOLTSVILLE NEW YORK NY
00544 40.81718 -73.04536 HOLTSVILLE NEW YORK NY
00601 18.165273 -66.722583 ADJUNTAS PUERTO RICO PR
00602 18.393103 -67.180953 AGUADA PUERTO RICO PR
00603 18.455913 -67.14578 AGUADILLA PUERTO RICO PR

I think that my problem may be that I am assuming that the latitude and longitude are in radins. But they may be in degrees and I do not know how to tell the difference.

Have I provided enough information?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reessee is offline Offline
3 posts
since May 2006
May 11th, 2006
0

Re: My zipcode query is not returning the correct results

yes, those locations are in degrees
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
May 11th, 2006
0

Re: My zipcode query is not returning the correct results

Thank you for your help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reessee is offline Offline
3 posts
since May 2006
Nov 19th, 2008
0

Re: My zipcode query is not returning the correct results

May be something is wrong with your formula or data. The both you can find on Zip Postal Codes web site for example.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ashley1213 is offline Offline
1 posts
since Nov 2008
Nov 19th, 2008
0

Re: My zipcode query is not returning the correct results

Click to Expand / Collapse  Quote originally posted by ashley1213 ...
May be something is wrong with your formula or data. The both you can find on Zip Postal Codes web site for example.
While I don't want to discourage new members, you might want to look at the dates of previous messages. This thread has been dead for 2 and a half years.
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: ms sql
Next Thread in MS SQL Forum Timeline: [B]How will I connect MS SQL to java?[/B]





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC