| | |
My zipcode query is not returning the correct results
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2006
Posts: 3
Reputation:
Solved Threads: 0
The following query:
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:
MS SQL Syntax (Toggle Plain Text)
CREATE PROCEDURE GetDistance AS SELECT a.ZIPCODE, a.CITY, a.STATE, ROUND( (ACOS( (SIN(c.LATITUDE) * SIN(a.LATITUDE)) + (COS(c.LATITUDE) * COS(a.LATITUDE) * COS(a.LONGITUDE - c.LONGITUDE)) ) ) * 3963,1 ) AS distance FROM Zipcodes a, Zipcodes c WHERE ( ACOS( (SIN(c.LATITUDE) * SIN(a.LATITUDE)) + (COS(c.LATITUDE) * COS(a.LATITUDE) * COS(a.LONGITUDE - c.LONGITUDE)) ) ) * 3963 <= '10' AND c.ZIPCODE='80222' ORDER BY distance GO
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
•
•
Join Date: May 2006
Posts: 3
Reputation:
Solved Threads: 0
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?
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?
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
May be something is wrong with your formula or data. The both you can find on Zip Postal Codes web site for example.
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
•
•
•
•
May be something is wrong with your formula or data. The both you can find on Zip Postal Codes web site for example.
![]() |
Similar Threads
- Problem with MySQL Query (Database Design)
- mysql DELETE not working (PHP)
- pagination of mysql query results (PHP)
- VB and Excel. (Visual Basic 4 / 5 / 6)
- tan of circle how to get correct results (Visual Basic 4 / 5 / 6)
Other Threads in the MS SQL Forum
- Previous Thread: Problems with parameters and selectcommand
- Next Thread: [B]How will I connect MS SQL to java?[/B]
| Thread Tools | Search this Thread |





