MySQL Forums
Forum List  »  Triggers

Re: Can I place IF statement in trigger?
Posted by: William Chiquito
Date: September 26, 2007 06:28AM

Hi riko,

This script works well in SQLyog:
DELIMITER $$

DROP TRIGGER /*!50033 IF EXISTS */ `oldFields`$$

CREATE TRIGGER `oldFields` BEFORE UPDATE on `temp_user_attendance`
FOR EACH ROW
BEGIN
	DECLARE mychanged INT DEFAULT 0;
	IF NEW.item_name != OLD.item_name OR NEW.cat_no != OLD.cat_no OR NEW.description != OLD.description
	OR NEW.quantity != OLD.quantity OR NEW.unit_price != OLD.unit_price OR NEW.quotation_no != OLD.quotation_no
	OR NEW.size != OLD.size OR NEW.comment != OLD.comment THEN
		SET mychanged = 1;
	END IF;
	IF mychanged = 1 THEN
		INSERT INTO notification_mail
		SET item_id = NEW.item_id,
		create_time = NOW(),
		mail_to = OLD.end_user,
		item_name = NEW.item_name,
		cat_no = NEW.cat_no,
		description = NEW.description,
		quantity = NEW.quantity,
		unit_price = NEW.unit_price,
		size = NEW.size,
		quotation_no = NEW.quotation_no,
		comment = NEW.comment;
	END IF;
END$$

DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
52591
August 09, 2007 12:37AM
15328
September 24, 2007 08:59PM
4935
September 25, 2007 09:30PM
Re: Can I place IF statement in trigger?
5138
September 26, 2007 06:28AM
3904
September 27, 2007 09:04PM
5357
September 29, 2007 12:12AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.