DELIMITER $$ CREATE
    /*[DEFINER = { user | CURRENT_USER }]*/
    PROCEDURE `gdims`.`PRO_EMERGENCY_COUNT_YEAR`(
town   int,      -- 镇乡 -1为全部
place  int     -- 片所  -1为全部
    )
    
BEGIN
     DECLARE parm1 int;
     set @parm1 = 2000;
     CREATE TABLE MyTempTable (_year int);
     while (parm1<=year(GETDATE())) 
insert into MyTempTable values (parm1);
        set @parm1 = parm1+1;
     end while;
END$$ 
    select t1.*,
t_num= case when t2.num is null then 0 
else num end   
from MyTempTable t1 left join (
select year(tisd_happen_time) as t_year,count(is_add) as num from tisd_quickly  
                where  (tisd_town =town or -1=town) and (place_name=place or -1=place) 
                group by year(tisd_happen_time)
) t2  on t1._year = t2.t_year -- 将临时表和 按年分类统计的表格进行左关联 达到期望的要求
DELIMITER ; 
-------------------------------------------------------------------------------------------
语法错误,怎么改,有人知道没?
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert into MyTempTable values (parm1)
        set @parm1 = parm1+1
     end w' at line 13
(0 ms taken)