title: MySQL stored procedure with variable argument list
body: <p>I have made a stored procedure. I want it to filter the data by different parameters. If I pass one parameter, it should be filtered by one; if I pass two, it should be filtered by two, and so on, but it is not working.</p>
  
  <p>Can anyone help me please?</p>
  
  <pre><code>DROP PROCEDURE IF EXISTS medatabase.SP_rptProvince2;
  CREATE PROCEDURE medatabase.`SP_rptProvince2`(
   IN e_Region VARCHAR(45)
    )
  BEGIN
  
   DECLARE strQuery VARCHAR(1024);
   DECLARE stmtp   VARCHAR(1024);
    SET @strQuery = CONCAT('SELECT * FROM alldata where 1=1');
    IF e_region IS NOT NULL THEN
     SET @strQuery = CONCAT(@strQuery, ' AND (regionName)'=e_Region);
    END IF;
  
   PREPARE  stmtp FROM  @strQuery;
   EXECUTE  stmtp;
  END;
  </code></pre>