title: how to use dynamic query inside a function
body: <p>i'm trying to create a function GETUSERPROP(prop, filter_prop, filter_value) that selects one item in database filtering by property and value</p>
  
  <pre><code>SET @_GET_PROP      = "name";
  SET @_FILTER_PROP   = "id";
  SET @_FILTER_VALUE  = "15";
  
  SET @q = CONCAT(
      ' SELECT ', 
      @_GET_PROP,
      ' FROM MYVIEW '
      ' WHERE 1 ',    
      ' AND (`', @_FILTER_PROP, '` = "', @_FILTER_VALUE, '") '
  );
  PREPARE stmt FROM @q;
  EXECUTE stmt;
  </code></pre>
  
  <p>the query outside function is running fine, but when I try to put this inside a function, I get the error</p>
  
  <pre><code>mysql dynamic sql is not allowed in stored function or trigger
  </code></pre>
  
  <p>I need this as a function to use inside other queries, like this:</p>
  
  <pre><code>SELECT 
      GETUSERPROP("name", "id", "15") AS name,
      GETUSERPROP("age",  "id", "15") AS age
  </code></pre>