title: Stored Procedure (mysql) fails with "can't return a result set in the given context"
body: <p>I'm trying to get this SP to return (leave) if some conditions fails and so forth. </p>
  
  <p>This code validates and it saves the procedure, but when I call the procedure with:</p>
  
  <pre><code>CALL ACH_Deposit(30027616,3300012003,200.00,"USD", "127.0.0.1")
  </code></pre>
  
  <p>It fails with error: "Procedure can't return a result set in the given context"</p>
  
  <p>Does anyone have any idea on what the error is?</p>
  
  <p>Procedure code:</p>
  
  <pre><code>CREATE DEFINER=`redpass_web_urs`@`%` PROCEDURE `ACH_Deposit`(
  IN __Account_ID BIGINT,
  IN __To_Bank_Account BIGINT,
  IN __Amount DECIMAL(10,2),
  IN __Currency CHAR(3),
  IN __IP_Address VARCHAR(50)
  )
  COMMENT 'Makes a ACH deposit'
  BEGIN
  
  -- Declare Account Parameters
  DECLARE _Account_Status INT;
  DECLARE __Transaction_ID INT;
  DECLARE _Account_Type INT DEFAULT 0;
  DECLARE _Fee INT;
  
  SELECT              
      Account_Status AS _Account_Status,
      Account_Type AS _Account_Type
  FROM Account_Users 
  WHERE Account_ID = __Account_ID;
  
  main: BEGIN
  
      -- Step 1, is account active ?
      IF _Account_Status &lt;&gt; 1 THEN
          -- Account must be active (not restricted, closed etc)
          SELECT Response_Code, Description FROM ResponseCodes WHERE Response_Code = 106;
          LEAVE main; -- Here we die..
      END IF;
  
      -- Step 2, Calculate the FEE (Loading Funds with ACH)
      IF _Account_Type = 1 THEN
          -- Personal Account
          SET _Fee = (SELECT Fee_Template_Personal_1 FROM Fees WHERE Fee_Type_ID = __Fee_Type_ID);
  
      ELSE
          -- Business Account
          SET _Fee = (SELECT Fee_Template_Business_1 FROM Fees WHERE Fee_Type_ID = __Fee_Type_ID);
  
      END IF;
  
      -- Step 3, Check that Fee is not bigger then the actual amount
      IF _Fee &gt; __Amount THEN
  
          SELECT Response_Code, Description FROM ResponseCodes WHERE Response_Code = 108;
          LEAVE main; -- Here we die..
  
      END IF;
  
      -- If we come here, we can make the transactions
      INSERT INTO Bank_Transaction
         (Bank_Account_ID
         ,Transaction_Type
         ,Amount
         ,IP_Address
         ,Pending)
       VALUES
         (__To_Bank_Account
         ,11
         ,__Amount
         ,__IP_Address
         ,1); -- Reserverade pengar
  
      -- Transaction ID
      SET __Transaction_ID = (SELECT LAST_INSERT_ID());
  
      -- Deduct the Fee
      INSERT INTO Bank_Transaction
             (Bank_Account_ID
             ,Transaction_Type
             ,Amount
             ,Fee_Type_ID
             ,Fee_Transaction_ID)
          VALUES
             (__To_Bank_Account
             ,4
             ,-__Fee
             ,21
             ,__Transaction_ID);
  
  
  
  END main;
  
  SELECT Response_Code, Description, __Transaction_ID AS Transaction_ID
  FROM ResponseCodes 
  WHERE Response_Code = 1;
  
  END
  </code></pre>