title: MySQL, stored-function, using STRING variable as QUERY
body: <p>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 <code>get_district_part ((district_id INT,county_id INT,city_id INT,zip_id INT)) RETURNS INT</code> that references the table: </p>
  
  <pre><code>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)
  );
  </code></pre>
  
  <p><code>get_distrct_part</code> is meant to return the id of rows mathing <code>district_id</code> and some combination of <code>county_id</code>, <code>city_id</code>, and <code>zip_id</code>. 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.</p>
  
  <p>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.</p>