First starting with this table:
And your records:
My complete database code : pastebin.com/v30s9Aa1
I wanted to know how a trigger / procedure for when the quantidade field is zero, the line stow with fild ativo == 1 , it zero to set this record and after it to set 1 in the ativo field where the espera field is 1 . That is:
When quantidade == 0 where ativo == 1, to set ativo == 0 and then looking where espera == 1 and set ativo == 1
At the moment I have this trigger, that when the inventory is zero, disables and adds date in the field data_saida
CREATE TRIGGER `tr_setaDataeDesativa` BEFORE UPDATE ON `estoque_folha`
FOR EACH ROW
IF NEW.quantidade = 0 THEN
SET NEW.data_baixa = current_date;
SET NEW.ativo = '0';
ELSEIF NEW.quantidade > 0 THEN
SET NEW.data_baixa = 0000-00-00;
END IF
I need to create another trigger or can take advantage of this?
Thank you