Is this query the same as that query?
I am using zipfinder.cfc which utilizes the following query to retrieve zip codes within a certain bounds of another zip code. This query is the original query that was included in the cfc:
<cfquery name="TEST" datasource="TEST">
select zipcode as zip, state, city,
SQRT(
SQUARE(#lat_miles# * (ipLATITUDE - (#z1.latitude#)))
+
square(#lon_miles# * (ipLONGITUDE - (#z1.longitude#)))
) as dist
from ZipCodes
where latitude between #lat1# AND #lat2#
AND longitude between #lon1# AND #lon2#
order by dist asc
</cfquery>
However, that query seems to always throw this error:
Error Executing Database Query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(69.1 * (latitude - (38))) + SQUARE(54.5375842556 * (longitude - (-' at line 3 <br>The error occurred on line 167.
The error seems to stemming from the "SQUARE" and "square" uses within the sql, because when I remove them I have no errors. So I assume that both SQUARE and square, are squaring the equation that follows. So I changed the query to:
<cfquery name="TEST" datasource="TEST">
select zipcode as zip, state, city,
SQRT(
(#lat_miles# * (ipLATITUDE - (#z1.latitude#))) * (#lat_miles# * (ipLATITUDE - (#z1.latitude#)))
+
(#lon_miles# * (ipLONGITUDE - (#z1.longitude#)))* (#lon_miles# * (ipLONGITUDE - (#z1.longitude#)))
) as dist
from ZipCodes
where latitude between #lat1# AND #lat2#
AND longitude between #lon1# AND #lon2#
order by dist asc
</cfquery>
So now instead of it using a SQUARE function it just multiples the equation by itself, effectively squaring it. Now, this seems to be working with the exception that my results are not always accurate and often times missing many local zip codes within the bounds. So I am somewhat confused as to why I even had to change SQUARE in the first place. Is that an outdated function in mysql? So I suppose my question is, are these two queries the same? If not, how can I change it so I can utilize the SQUARE function in mysql so my results are more accurate. If they are the same, any ideas why my results would be inaccurate?
Thanks in advance,
Mark
