存储过程mysql语法

时间:2017-02-21 11:17:10

标签: mysql stored-procedures

请帮我解决这个存储过程中的错误:

 CREATE DEFINER=`root`@`localhost` PROCEDURE `repos`(IN `order_condition` VARCHAR(100) CHARSET utf8, IN `from_date` VARCHAR(255) CHARSET utf8, IN `to_date` VARCHAR(255) CHARSET utf8, IN `dept_id` TINYINT(4), IN `type` VARCHAR(15) CHARSET utf8, IN `search_value` VARCHAR(50) CHARSET utf8, IN `institutionid` INT(11))
    NO SQL
BEGIN

set @strWhere   = "";
set @strWhere   = CONCAT(@strWhere,"t1.inst_id = ",instid);
set @selectstr  = '';
set @selectstr2 = '';
set @joinstr    = '';
set @joinstr2   = '';
set @group2= '';

set @selectstr = CONCAT(",t2.`std_name`");
set @selectstr2= CONCAT(",t5.`student_name`,t5.`roll_no`,t5.`student_id`");
set @joinstr = CONCAT("left join standard_master as t2 on t1.`std_id`= t2.`std_id` ");
set @joinstr2 = CONCAT("left join student_det as t5 on t1.`std_id`= t5.`std_id` ");
set @strWhere = CONCAT(@strWhere," AND t1.std_id = ",dept_id);
set @group2= CONCAT("t5.`student_id`");


SET @query = CONCAT("select t1.* ",@selectstr," , t3.term_name, SUM(t4.amount) as fee_amount",@selectstr2," FROM inst_fee AS t1 ",@joinstr," left join term_master as t3 on t1.term_id = t3.term_id left join inst_amtdet as t4 on t4.masterid = t1.masterid ",@joinstr2,"  WHERE ",@strWhere,  " AND ",@group2,  " NOT IN (select id from student_master) Group by t1.f_name  ", order_condition);

PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

#select @query;


END

它显示语法错误:

  

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在' IN附近使用正确的语法(

请帮我修复错误。感谢

1 个答案:

答案 0 :(得分:0)

语法正确。它适用于新的MySQL服务器。

您可能使用旧的MySQL服务器,其中字符串参数不支持CHARSET子句。检查服务器版本的语法。