title: MYSQL Stored Procedure Not inserting
body: <p>I have a stored procedure that I am passing in 3 parameters (Variables) from PHP to.  I've verified the PHP code is getting and setting the values properly so I'm working exclusively with the parameters being set prior to execution.  Below is my stored procedure code.</p>
  
  <p>The issue is that I am trying to get the results of the 3rd Select statement to populate into the table defined by the <code>table_in</code> parameter but its returning 0 results.  I have tried piecing it together one statement at a time but ran into issues with the lat, lng statements.</p>
  
  <p>How do I fix this properly so that it will accept the parameters input and use those values properly and insert the appropriate output from the defined function called in the stored procedure?</p>
  
  <pre><code>CREATE PROCEDURE `sp_store_code_ms1`(IN `store_code_in` VARCHAR(10), IN `table_in` VARCHAR(20), IN `range_in` INT(2))
  BEGIN
      DECLARE cnt INT DEFAULT 0; 
      DECLARE lat DOUBLE DEFAULT 0;
      DECLARE lng DOUBLE DEFAULT 0;
  
      SELECT DISTINCT code 
      FROM `postal_code` AS `cnt`
      WHERE code = ('store_code_in')
      LIMIT 1;
  
      IF (`cnt` &gt; 0) THEN 
  
          SELECT DISTINCT store_code AS `cnt2` 
          FROM `table_in` 
          WHERE STORE_CODE = `store_code_in` 
          LIMIT 1;
  
          IF (`cnt2` &lt; 1) THEN 
  
              SELECT latitude, longitude INTO lat, lng 
              FROM `postal_code` 
              WHERE code = ('AB101AB');
  
              INSERT INTO `table_in` (`store_code`, `search_code`, `distance`) 
              SELECT ('store_code_in'), code
                  , fn_haversine(`lat`, `lng`, latitude, longitude) AS `distance` 
              FROM `postal_code` 
              HAVING `distance` &lt; `range_in`;
  
          END IF; 
  
      END IF;
  END 
  </code></pre>