title: Mysql function returning a value from a query
body: <p>i want to create a function which calculates a value using a query and I am having a problem returning the value: </p>
  
  <p>Shortened, my query is:</p>
  
  <pre><code>CREATE FUNCTION func01(value1 INT , monto DECIMAL (10,2)) RETURNS DECIMAL(10,2)
  BEGIN
  SET @var_name = 0;
  select @var_name=if(value1 = 1,monto * table.divisa_dolar,table.monto *divisa_euro) from table where data_init = 1;
  return @var_nam;
  END
  </code></pre>
  
  <p>I get a SQL syntax error. </p>
  
  <blockquote>
    <p>SQL Error (1064): You have an error in your SQL syntax;</p>
  </blockquote>