0

First starting with this table:

Table estoque_folha

And your records:

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

Tin Tran
  • 6,194
  • 3
  • 19
  • 34
Vitor
  • 3
  • 1
  • you could probably add your logics into the same trigger if it's all in the same table – Tin Tran Apr 20 '16 at 19:09
  • your trigger looks wrong, it needs the a semicolon after `END IF` and `0000-00-00` should be in quotes..and it's not a valid date either, if you don't want a date you should set it to NULL – Tin Tran Apr 20 '16 at 19:13

0 Answers0