Create SQL Query in function or PROCEDURE I am trying to create function inside MySQL to create several queries for example :

    DELIMITER |
    CREATE PROCEDURE queryBuilder(_tableName varchar(100))
    BEGIN
          SET @str_query = 'SET @countRows = 0;SELECT COUNT(*) INTO @countRows FROM';
          SET @str_query = CONCAT(@str_query,_tableName, '; SELECT @countRows');

         PREPARE stmt1 FROM @str_query;

         EXECUTE stmt1;

   END|
   DELIMITER;


but it doesn't work? how can i change to work? I know i can create IF statement but i want something with more flexibility.
Don't set @countRows twice.
Don't combine two queries into a single "statement".
Watch out for syntax errors when concatenating without a space.
SELECT @str_query; for debugging.