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 ;

MySql IF ELSE EXISTS Update Trigger

DELIMITER $$

DROP TRIGGER `rfc`.`insert_send_query_update`$$

CREATE TRIGGER `rfc`.`insert_send_query_update` AFTER UPDATE on `rfc`.`send_query`
FOR EACH ROW BEGIN

 DECLARE P1,P2 VARCHAR(50);

 IF (EXISTS (SELECT send_query_Date_Rcv1 FROM report_one WHERE fileSerial = OLD.fileSerial AND (send_query_Date_Rcv1 IS NULL OR send_query_Date_Rcv1 =''))) THEN
    
   UPDATE report_one SET send_query_Date_Rcv1 = (NEW.received_date),Send_Query_SLA1 = NEW.Sq_SlaDate WHERE fileSerial = OLD.fileSerial;

 ELSE IF (EXISTS (SELECT send_query_Date_Rcv2 FROM report_one WHERE fileSerial = OLD.fileSerial AND (send_query_Date_Rcv2 IS NULL OR send_query_Date_Rcv2 =''))) THEN
  
   UPDATE report_one SET send_query_Date_Rcv2 = (NEW.received_date),Send_Query_SLA2 = NEW.Sq_SlaDate WHERE fileSerial = OLD.fileSerial;

 ELSE IF (EXISTS (SELECT send_query_Date_Rcv3 FROM report_one WHERE fileSerial = OLD.fileSerial AND (send_query_Date_Rcv3 IS NULL OR send_query_Date_Rcv3 =''))) THEN

     UPDATE report_one SET send_query_Date_Rcv3 = (NEW.received_date),Send_Query_SLA3 = NEW.Sq_SlaDate WHERE fileSerial = OLD.fileSerial;
 ELSE
     UPDATE report_one SET send_query_Date_Rcv4 = (NEW.received_date),Send_Query_SLA4 = NEW.Sq_SlaDate WHERE fileSerial = OLD.fileSerial;
 END IF;
 END IF;
 END IF;


END;$$

DELIMITER ;

MySql Update Trigger

DELIMITER $$

DROP TRIGGER `rfc`.`insert_approval_data_update`$$

CREATE TRIGGER `rfc`.`insert_approval_data_update` AFTER UPDATE on `rfc`.`dbrassessment`
FOR EACH ROW BEGIN
UPDATE report_one SET approved_ammount = NEW.LoanAmountRec,approved_tenor = NEW.TenureRec,Interest_Rate = NEW.InterestRateRec,EMI = NEW.EmiRec,dbr_ratio = NEW.DbrAsPerSlabrec WHERE fileSerial = NEW.fileSerial;
END$$

DELIMITER ;

MySql Insert Trigger



 DELIMITER $$

DROP TRIGGER `rfc`.`after_insert_new_file`$$

create trigger `rfc`.`after_insert_new_file` AFTER INSERT on `rfc`.`customer_info`
for each row BEGIN
INSERT INTO report_one (fileSerial,Status,Sla_Date,Source_id,Source_Name,Cluster,app_Date,applicants_Name,Applied_Ammount,Applied_Tenor,age,Home_Phone,Present_Area,Parmanent_Area)
        VALUES (NEW.fileSerial,NEW.status,NEW.Sla_Date,NEW.introducer_id,NEW.Branch,NEW.Cluster,NEW.AppDate,NEW.applicantsName,NEW.applied_amount,NEW.loanTenor,NEW.ageCalculate,NEW.homePhoneMobile,NEW.presentArea,NEW.permanentArea);
END;
$$

DELIMITER ;