I'm trying to get all locations stored in the database with an sql statement described here
My sql statement is:
SELECT TOP(10)
*,
(
6371 *
acos(
cos(
radians(<cfqueryparam cfsqltype="CF_SQL_Numeric" value="#FORM.latitude#">)
) *
cos(
radians( custLat )
) *
cos(
radians( custLong ) -
radians(<cfqueryparam cfsqltype="CF_SQL_Numeric" value="#FORM.longtitude#">)
) +
sin(
radians(<cfqueryparam cfsqltype="CF_SQL_Numeric" value="#FORM.latitude#">)
) *
sin(
radians( custLat )
)
)
) AS distance
FROM customers
HAVING distance < 25
ORDER BY distance;
Problem is I get an error and can't figure out why...
error: Invalid column name 'distance'.
on this line: radians(<cfqueryparam cfsqltype="CF_SQL_Numeric" value="#FORM.latitude#">)
(the second occurrence)
Why do I get this error and how do I fix it?