distance between zip codes

G

Guest

I don't know if this is possible but I have a table with all of the zip codes
and their corresponding latitude and longitude. I have a query that
calculates the distance between. The only thing that is not working is when
the zip codes is the same. Instead of saying the distance is 0 it just says
#error. I was wondering if there is anyway to have the query check to see if
the zip codes is the same and then to set the value equal to 0 or else to do
the calculation. The query is:

SELECT
(Atn(-((Sin(z1.latitude*0.017453293)*Sin(z2.latitude*0.017453293))+(Cos(z1.latitude*0.017453293)*Cos(z2.latitude*0.017453293)*Cos((z2.longitude*0.017453293)-(z1.longitude*0.017453293))))/Sqr(-((Sin(z1.latitude*0.017453293)*Sin(z2.latitude*0.017453293))+(Cos(z1.latitude*0.017453293)*Cos(z2.latitude*0.017453293)*Cos((z2.longitude*0.017453293)-(z1.longitude*0.017453293))))*((Sin(z1.latitude*0.017453293)*Sin(z2.latitude*0.017453293))+(Cos(z1.latitude*0.017453293)*Cos(z2.latitude*0.017453293)*Cos((z2.longitude*0.017453293)-(z1.longitude*0.017453293))))+1))+2*Atn(1))*3956 AS distance, z1.ZipCode AS Zip1, z2.ZipCode AS Zip2
FROM [zip code info] AS z1, [zip code info] AS z2;
 
J

Joseph Meehan

Dan said:
I don't know if this is possible but I have a table with all of the
zip codes
and their corresponding latitude and longitude. I have a query that
calculates the distance between. The only thing that is not working
is when
the zip codes is the same. Instead of saying the distance is 0 it
just says #error. I was wondering if there is anyway to have the
query check to see if
the zip codes is the same and then to set the value equal to 0 or
else to do
the calculation. The query is:

SELECT
(Atn(-((Sin(z1.latitude*0.017453293)*Sin(z2.latitude*0.017453293))+(Cos(z1.latitude*0.017453293)*Cos(z2.latitude*0.017453293)*Cos((z2.longitude*0.017453293)-(z1.longitude*0.017453293))))/Sqr(-((Sin(z1.latitude*0.017453293)*Sin(z2.latitude*0.017453293))+(Cos(z1.latitude*0.017453293)*Cos(z2.latitude*0.017453293)*Cos((z2.longitude*0.017453293)-(z1.longitude*0.017453293))))*((Sin(z1.latitude*0.017453293)*Sin(z2.latitude*0.017453293))+(Cos(z1.latitude*0.017453293)*Cos(z2.latitude*0.017453293)*Cos((z2.longitude*0.017453293)-(z1.longitude*0.017453293))))+1))+2*Atn(1))*3956
AS distance, z1.ZipCode AS Zip1, z2.ZipCode AS Zip2 FROM [zip code
info] AS z1, [zip code info] AS z2;

How about prefacing the whole thing with a simple IF Zip1 = Zip2 (0,
(your formula))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top