title: MYSQL Function IF Syntax
body: <p>I am trying to write one function with IF and I am getting Error</p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use
    near '' at line 8 Code 1064</p>
  </blockquote>
  
  <p>This is the function.</p>
  
  <pre><code>DELIMITER $$
  
  DROP FUNCTION IF EXISTS `my_fun` $$
  CREATE FUNCTION `my_fun` (nid INT) RETURNS VARCHAR(200)
  BEGIN
  DECLARE abc varchar(100);
  SELECT foo INTO abc FROM my_table WHERE bar = nid;
  IF abc = ''
  THEN
  SELECT foo INTO abc FROM my_table WHERE bar = -1;
  RETURN abc;
  END $$
  
  DELIMITER ;
  </code></pre>
  
  <p>Am not sure whats the <a href="http://dev.mysql.com/doc/refman/5.5/en/if.html" rel="nofollow">syntax</a> here , I tried <code>IF abc IS NULL</code> also.
  I just want to check if first select statement returned empty value then execute another statement.</p>