MySQL Forums
Forum List  »  Triggers

Date check on insert
Posted by: mitch mitch
Date: January 28, 2012 01:03PM

Hi, I was wondering how to verify if a date from a column is smaller than another date from another column.

Bascially, we'll say it's a promotion that goes on from 02-01-2012('promotion_start' column) until 03-01-2012('promotion_end' column). That is good but, what if the ending date is, 01-01-2012('promotion_end' column)?
If it's not good I would like to raise and error/exception.

I tried making a trigger but it's been a while and I could not get it to work. (Kinda rusty on triggers and I couldnt find any decent exemple about dates).
Here it is:

CREATE TRIGGER `test` BEFORE INSERT ON `promotion`
FOR EACH ROW BEGIN BEGIN IF NEW.DATE_FIN_PROMOTION < NEW.DATE_DEBUT_PROMOTION
THEN call exception('Promotion cannot end before start.'); END IF; END; END;

Also, if it matters I use HeidiSQL.

Thanks



Edited 1 time(s). Last edit at 01/28/2012 01:05PM by mitch mitch.

Options: ReplyQuote


Subject
Views
Written By
Posted
Date check on insert
3069
January 28, 2012 01:03PM
1327
January 30, 2012 11:15AM
1026
January 30, 2012 05:41PM


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.