I was wondering if it is possible in a mysql stored-function or stored-procedure compose a mysql query as a string variable you can execute later? I have a stored-function get_district_part ((district_id INT,county_id INT,city_id INT,zip_id INT)) RETURNS INT
that references the table:
CREATE TABLE IF NOT EXISTS `modx`.covereage_district_part(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
districtID INT NOT NULL,
countyID INT,
cityID INT,
zipID INT,
FOREIGN KEY (districtID) REFERENCES `modx`.coverage_district (id),
FOREIGN KEY (countyID) REFERENCES `modx`.coverage_county (id),
FOREIGN KEY (cityID) REFERENCES `modx`.coverage_city (id),
FOREIGN KEY (zipID) REFERENCES `modx`.coverage_zip (id)
);
get_distrct_part
is meant to return the id of rows mathing district_id
and some combination of county_id
, city_id
, and zip_id
. The thing is I want to return the id of the row matching the exact combination of ids not the ids of rows that contain any of those ideas. To do that, I am wanting to segment my query statement so it is built specific to the ids provided. I am trying to not have to match nulls if I can.
I realize this can be easily done with PHP, but I would like the do this as mysql stored process if I can for no other reason then all the other functions for this are stored processes.