Tuesday, July 30, 2013

MySql Variable Declare SELECT Trigger

DELIMITER $$

DROP TRIGGER `rfc`.`update_cpv`$$

CREATE TRIGGER `rfc`.`update_cpv` AFTER UPDATE on `rfc`.`cpv_info`
FOR EACH ROW BEGIN
 
 DECLARE P1,P2 VARCHAR(50);

 SELECT orgName INTO P1 FROM cpv_info WHERE id = OLD.id;

 IF (EXISTS (SELECT Bank_Name_1 FROM report_one WHERE fileSerial = OLD.fileSerial AND Bank_Name_1 =P1)) THEN
    
   UPDATE report_one SET cpv_rcv_Date = (NEW.completingDate),CPV_Status = NEW.status,Rcv_Date_1=NEW.completingDate WHERE fileSerial = OLD.fileSerial;

 ELSE IF (EXISTS (SELECT Bank_Name_2 FROM report_one WHERE fileSerial = OLD.fileSerial AND Bank_Name_2 =P1)) THEN
  
    UPDATE report_one SET cpv_rcv_Date = (NEW.completingDate),CPV_Status = NEW.status,Rcv_Date_2=NEW.completingDate WHERE fileSerial = OLD.fileSerial;

 ELSE IF (EXISTS (SELECT Bank_Name_3 FROM report_one WHERE fileSerial = OLD.fileSerial AND Bank_Name_3 =P1)) THEN

     UPDATE report_one SET cpv_rcv_Date = (NEW.completingDate),CPV_Status = NEW.status,Rcv_Date_3=NEW.completingDate WHERE fileSerial = OLD.fileSerial;

END IF;
 END IF;
 END IF;
END$$

DELIMITER ;

No comments:

Post a Comment