MySQL Forums
Forum List  »  Triggers

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

Hi riko,

Try:
CREATE TABLE `notification_mail` (
  `item_id` int(11) NOT NULL auto_increment,
  `item_name` varchar(15) collate latin1_general_ci default NULL,
  `cat_no` varchar(5) collate latin1_general_ci default NULL,
  `description` varchar(100) collate latin1_general_ci default NULL,
  `quantity` int(11) default NULL,
  `unit_price` int(11) default NULL,
  `quotation_no` int(11) default NULL,
  `size` varchar(10) collate latin1_general_ci default NULL,
  `comment` text collate latin1_general_ci,
  PRIMARY KEY  (`item_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci

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
3904
September 27, 2007 09:04PM
Re: Can I place IF statement in trigger?
5781
September 28, 2007 02:35AM
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.