title: MySQL Returning Value in Stored Proc
body: <p>This is a very easy stored proc but I can't get it to work.  I want to count up the number of records based upon some filters passed in.  The where clause works perfectly (it's used in another stored proc to return values).  In this Stored proc, I just want the TOTAL COUNT based on the "where".  I'm calling it like this:
  call countthem('column1', 'AA', 'LIKE', @outfiltercount);
  But, I'm getting the error message back "Error Code 1327: Undeclared variable: countit"</p>
  
  <pre><code>CREATE DEFINER=`root`@`%` PROCEDURE countthem(
    IN infilterfield  varchar(25),  
    IN infiltervalue varchar(100), 
    IN infiltertype varchar(10),
    OUT outfiltercount INT)
  
  
  BEGIN
  
  DECLARE SQLStatement varchar(255);
  DECLARE countit INT;
  
  
  SET @filterfield = infilterfield;
  SET @filtervalue = infiltervalue; 
  SET @filtertype = infiltertype;
  
  SET outfiltercount = 0;
  
  SET @filterstring = '';
  
  IF infiltertype is not null and infiltertype != ''
  
    THEN
  
       IF infiltertype like 'EQUALS'
          THEN
             SET @filterstring = CONCAT(' WHERE ', @filterfield, ' ', ' = ', ' \'', @filtervalue, '\'');
       ELSE
             SET @filterstring = CONCAT(' WHERE ', @filterfield, ' ', ' LIKE ', ' \'%', @filtervalue, '%\'');
       END IF;
  END IF;  
  
  SET @SQLStatement = CONCAT('select count(*) into countit from vsltable ', @filterstring);
  
  PREPARE stmt FROM @SQLStatement;
  
  EXECUTE stmt;   
  
  set outfiltercount = countit;
  
  END$$
  DELIMITER ;
  </code></pre>