title: MySQL How to get results after PREPARE and EXECUTE in Stored Procedure?
body: <p>My current code is :</p>
  
  <pre><code>DELIMITER \\
  
  CREATE PROCEDURE sample (IN _car VARCHAR(15))
      BEGIN
          DECLARE _a INTEGER;
          SET @s = CONCAT('SELECT COUNT(*) FROM train WHERE ', _car, '&lt;=0;');
          PREPARE stmt1 FROM @s;
          EXECUTE stmt1;
          DEALLOCATE PREPARE stmt1;
  
  END\\
  </code></pre>
  
  <p>But I wanted to capture the answer of the SELECT statement to my _a variable.</p>
  
  <p>I tried changing my code to </p>
  
  <pre><code>SET @s = CONCAT('SELECT COUNT(*) INTO', _a,' FROM train WHERE ', _car, '&lt;=0;');
  </code></pre>
  
  <p>But that didn't work.</p>
  
  <p>Help, please?</p>
  
  <p>SOLVED!</p>
  
  <pre><code>DELIMITER \\
  
  CREATE PROCEDURE sample (IN _car VARCHAR(15))
      BEGIN
          DECLARE _a INTEGER;
          SET @var = NULL;
          SET @s = CONCAT('SELECT COUNT(*) INTO @var FROM train WHERE ', _car, '&lt;=0;');
          PREPARE stmt1 FROM @s;
          EXECUTE stmt1;
          SELECT @var;
          DEALLOCATE PREPARE stmt1;
  END\\
  </code></pre>
  
  <p>:D</p>