title: Mysql : Not allowed to return a result set from a function
body: <p>I have write one function  but getting this error  <strong>Not allowed to return a result set from a function</strong></p>
  <pre class="lang-sql prettyprint-override"><code>DELIMITER $$
  
  CREATE FUNCTION getTestFunction
  (
      p_ParentID int,
      p_ListName nvarchar(50),
      p_Type nvarchar(50),
      p_Count int 
  )
  RETURNS nvarchar(2000)
  BEGIN
      DECLARE p_KeyValue nvarchar(2000);
      DECLARE p_ListValue nvarchar(2000);
      DECLARE p_TextValue nvarchar(2000);
      DECLARE p_ReturnValue nvarchar(2000);
      DECLARE p_Key nvarchar(2000);
      
      IF p_ParentID = 0 THEN
          IF p_Count = 0 THEN
              SET p_ReturnValue = '';
          ELSE
              SET p_ReturnValue = p_ListName;
          END IF;
      ELSE
      
              SELECT  p_KeyValue = ListName + '.' + Value
                  
                  FROM ListsTable
                  WHERE EntryID = p_ParentID  LIMIT 1 ;
      RETURN p_ReturnValue;
              If p_Type = 'ParentKey' Or (p_Type = 'ParentList' AND p_Count &gt; 0) THEN
                  SET p_ReturnValue = p_KeyValue;
              ELSE 
                  IF p_Type = 'ParentList' THEN
                      SET p_ReturnValue = p_ListValue;
                  ELSE
                      SET p_ReturnValue = p_TextValue;
                  END IF;
              END IF;
  
              IF p_Count &gt; 0 THEN
                  If p_Count = 1 AND p_Type = 'ParentList' THEN
                      SET p_ReturnValue = p_ReturnValue + ':' + p_ListName;
                  ELSE
                      SET p_ReturnValue = p_ReturnValue + '.' + p_ListName;
                  END IF;
              END IF;
          
      END IF; 
      RETURN p_ReturnValue;
  END$$
  DELIMITER ;
  </code></pre>