PDA

View Full Version : Please Help With Query - Syntax error


DigitalFusion
03-03-2008, 09:56 PM
This is the query I am trying to run with an access database:

SELECT DealerName, DealerAddress, DealerState, DealerCity,DealerZip, ZIP_name, ZIP,DealerTollFreePhone, DealerPhone, Latitude, Longitude, ROUND((ACOS((SIN(45.412894/57.2958) * SIN(latitude/57.2958)) +(COS(45.412894/57.2958) * COS(latitude/57.2958) * COS(longitude/57.2958 - -92.633615/57.2958)))) * 3963) AS distance FROM Dealers INNER JOIN US_ZIP ON Dealers.DealerZIP = US_ZIP.ZIP

The problem I have is that Access does not have a ACOS function. So the following does not work:

ROUND((ACOS((SIN("&iStartLat&"/57.2958) * SIN(latitude/57.2958)) + (COS("&iStartLat&"/57.2958) * COS(latitude/57.2958) * COS(longitude/57.2958 - "&iStartLong&"/57.2958)))) * 3963) AS distance


I found a post from somewhere that said:
You can derive the ArcCos function using the following alternative: Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)

My head starts hurting the second I even think about trying to convert that query with ACOS to this latter version.

DigitalFusion
03-03-2008, 10:10 PM
cleaning up

Spudhead
03-04-2008, 02:16 PM
What database are you using?

DigitalFusion
03-04-2008, 06:05 PM
access. I know it is because of the formula, but my eyes go cross-eyed when I google that formula and try to plug it into a SQL query via an ASP page

DigitalFusion
03-04-2008, 07:41 PM
cleaning up

DigitalFusion
03-04-2008, 08:20 PM
oh man... I need to just delete all these posts and start over. I found my syntax error. However, my formula is still screwed up. Places that are less than 20 miles from here are coming up as 2000+ miles away.