MySQL过程插入错误的行

时间:2014-04-08 08:30:26

标签: mysql

MySQL我的程序如下:

   CREATE DEFINER = `root`@`localhost` PROCEDURE `save_inst`(IN stid INT,IN cid INT,IN    plan_name VARCHAR(100),IN bnch INT)

  BEGIN
  DECLARE done INT DEFAULT FALSE;
  DECLARE crid INT;
  DECLARE dat VARCHAR(20);
  DECLARE cur1 CURSOR FOR SELECT courseid,date_add(datee,INTERVAL @r:=@r+@rr MONTH) dat from stdebitfees,(SELECT @r:=(SELECT if(c.yearsem='YEAR',-12,if(c.yearsem='SEM',-6,-1)) ss from course c WHERE c.uid=cid) b,@rr:=abs(@r)) a WHERE addable_to_inst='YES' and sid=stid GROUP BY courseid;

  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

  OPEN cur1;
  read_loop: LOOP
  FETCH cur1 INTO crid, dat;
    IF done THEN
      LEAVE read_loop;
    END IF;
    INSERT into student_inst (SELECT null,b.sid,@rownum:=@rownum+1 'instid',DATE_ADD(STR_TO_DATE(dat,'%Y-%m-%d'),INTERVAL a.dt*(@rownum-1) MONTH) as dat,DATE_ADD(STR_TO_DATE(dat,'%Y-%m-`enter code here`%d'),INTERVAL a.dt*(@rownum-1) MONTH) as dat1,round(a.per/100.0*amt) as inst,b.branchid,b.userid,b.sessionid,b.uniid,b.courseid,b.batchid,'UNPAID' c1,'NOT-APPLY' c2,if(b.courseid=cid,'RUNNING','NOT-APPLY') c3 from((SELECT freq_in_month as dt,per FROM master_inst m WHERE m.branchid=bnch and  plan_name=plan_name) a,(SELECT sid,datee,sum(amount) as amt,branchid,userid,sessionid,uniid,courseid,batchid from stdebitfees WHERE sid=stid and courseid=crid and addable_to_inst='YES') b,(SELECT @rownum:=0) r))  ;

  END LOOP;

  CLOSE cur1;

   END;

我有一个为期3年的课程,学生将在一年内分3期付款,3年内9年付费,所以在入学时将所有分期付款插入分期付款表

请建议我哪里弄错了。

0 个答案:

没有答案