Basically I have the following stored procedure:
BEGIN
SET @query := CONCAT("SELECT *,
sqrt(
(POW(a.Latitude - co.CenterLatitude, 2)* 68.1 * 68.1) +
(POW(a.Longitude - co.CenterLongitude, 2) * 53.1 * 53.1)
) AS distance
FROM table1 as r
JOIN table2 as co ON co.field1 = r.field2
JOIN table3 AS a ON r.field1 = a.field2
WHERE ",rid);
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
It has the following passing through:
IN rid varchar(500), lat double, lon double
But I need to pass in the latitude and longitude variables. I have tried setting them then adding them into the query but it is not recognizing them. This is what I am trying to do which is not successful:
BEGIN
SET @lat := lat;
SET @lon := lon;
SET @query := CONCAT("SELECT *,
sqrt(
(POW(a.Latitude - @lat, 2)* 68.1 * 68.1) +
(POW(a.Longitude - @lon, 2) * 53.1 * 53.1)
) AS distance
FROM table1 as r
JOIN table2 as co ON co.field1 = r.field2
JOIN table3 AS a ON r.field1 = a.field2
WHERE ",rid);
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
I am not sure how to accomplish this. Does anyone have any suggestions? Thank you in advance!!
rid?