My zipcode query is not returning the correct results

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 3
Reputation: Reessee is an unknown quantity at this point 
Solved Threads: 0
Reessee Reessee is offline Offline
Newbie Poster

My zipcode query is not returning the correct results

 
0
  #1
May 10th, 2006
The following query:
  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: My zipcode query is not returning the correct results

 
0
  #2
May 10th, 2006
give us table setup and what data you have in those tables
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3
Reputation: Reessee is an unknown quantity at this point 
Solved Threads: 0
Reessee Reessee is offline Offline
Newbie Poster

Re: My zipcode query is not returning the correct results

 
0
  #3
May 10th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: My zipcode query is not returning the correct results

 
0
  #4
May 11th, 2006
yes, those locations are in degrees
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3
Reputation: Reessee is an unknown quantity at this point 
Solved Threads: 0
Reessee Reessee is offline Offline
Newbie Poster

Re: My zipcode query is not returning the correct results

 
0
  #5
May 11th, 2006
Thank you for your help.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 1
Reputation: ashley1213 is an unknown quantity at this point 
Solved Threads: 0
ashley1213 ashley1213 is offline Offline
Newbie Poster

Re: My zipcode query is not returning the correct results

 
0
  #6
Nov 19th, 2008
May be something is wrong with your formula or data. The both you can find on Zip Postal Codes web site for example.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: My zipcode query is not returning the correct results

 
0
  #7
Nov 19th, 2008
Originally Posted by ashley1213 View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC