Mysql 存储过程中的CONCAT返回null

Mysql 存储过程中的CONCAT返回null,mysql,stored-procedures,Mysql,Stored Procedures,请告诉我错误在哪里? 错误似乎在第一行 错误代码:1064。您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解在第1行使用接近“NULL”的正确语法 如果任何参数为NULL,CONCAT将返回NULL 这一点可以通过以下示例进行说明: 您可以在这里找到一些有关使用空值的文档:您希望在这里发生什么?这是什么数据库引擎?MSSQL?是的,它是MYSQL。只是想执行在select之前缺少动态sql语句数据空间:,tmpTableName、SELECT、id、…@Nadeem_MK-以

请告诉我错误在哪里? 错误似乎在第一行
错误代码:1064。您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解在第1行使用接近“NULL”的正确语法

如果任何参数为NULL,CONCAT将返回NULL

这一点可以通过以下示例进行说明:


您可以在这里找到一些有关使用空值的文档:

您希望在这里发生什么?这是什么数据库引擎?MSSQL?是的,它是MYSQL。只是想执行在select之前缺少动态sql语句数据空间:,tmpTableName、SELECT、id、…@Nadeem_MK-以及每个字段id、thisDate等之间。但这不是空值的原因!错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解第1行Direct insert语句(如insert into tmpTableName select id、thisDate、timestampaddMICROSECOND、-1、nextDate、vehicleCount、productId)中使用接近“NULL”的正确语法;工作非常好,但我的要求是要有动态表名..这是准备好的语句,但与select一起工作不正常..上面我简要地编辑了我的问题..请看一下谢谢。。正如您所提到的,有一个空变量。
     -- --------------------------------------------------------------------------------
    -- Routine DDL
    -- Note: comments before and after the routine body will not be stored by the server
    -- --------------------------------------------------------------------------------
    DELIMITER $$

    CREATE DEFINER=`advancebooker`@`%` PROCEDURE `make_intervals`(startdate datetime, enddate datetime, intval integer, unitval varchar(10), tmpTableName varchar(100))
    BEGIN
    -- *************************************************************************
    --
    -- Description:
    -- This procedure creates a temporary table named time_intervals with the
    -- interval_start and interval_end fields specifed from the startdate and
    -- enddate arguments, at intervals of intval (unitval) size.
    -- *************************************************************************
       declare thisDate datetime;
       declare nextDate datetime;
       declare id INT;
       declare  vehicleCount int default 0;
       declare productId int default 0; 
       set thisDate = startdate;





       -- *************************************************************************
       -- Drop / create the  table
       -- *************************************************************************

      SET @sql = CONCAT('CREATE TABLE IF NOT EXISTS ',tmpTableName, '(id INT(11) NOT NULL  AUTO_INCREMENT, interval_start DATETIME, interval_end DATETIME, vehicleCount INT(20), productId INT(10), PRIMARY KEY (id))');
      PREPARE stmt FROM @sql;
      EXECUTE stmt;
      DEALLOCATE PREPARE stmt;



       -- *************************************************************************
       -- Loop through the startdate adding each intval interval until enddate
       -- *************************************************************************
       repeat
          select
             case unitval
                when 'MICROSECOND' then timestampadd(MICROSECOND, intval, thisDate)
                when 'SECOND'      then timestampadd(SECOND, intval, thisDate)
                when 'MINUTE'      then timestampadd(MINUTE, intval, thisDate)
                when 'HOUR'        then timestampadd(HOUR, intval, thisDate)
                when 'DAY'         then timestampadd(DAY, intval, thisDate)
                when 'WEEK'        then timestampadd(WEEK, intval, thisDate)
                when 'MONTH'       then timestampadd(MONTH, intval, thisDate)
                when 'QUARTER'     then timestampadd(QUARTER, intval, thisDate)
                when 'YEAR'        then timestampadd(YEAR, intval, thisDate)
             end into nextDate;



       SET @sql = CONCAT("INSERT INTO ",tmpTableName," SELECT ", id, thisDate,TIMESTAMPADD(MICROSECOND, -1, nextDate), vehicleCount , productId);
       SET thisDate = nextDate;
       PREPARE stmt FROM @sql;
       EXECUTE stmt;
       DEALLOCATE PREPARE stmt;
       until thisDate >= enddate
       end repeat;
      END

When i debug the above stored proc in the SET @sql = CONCAT("INSERT INTO ",tmpTableName," ... line  I am getting null value?