Trigger to update several lines MariaDB

0

I'm trying to create a trigger to update the stock value of the products table, according to the status of the note.

ex. on the note have 2 products

1 | Qty: 3

2 | Qty: 5

When the status is updated to "0" which means that the note has been canceled, the values should go back to the stock

I tried to create the following trigger

IF (NEW.STATUS = 0) THEN
  SELECT ID_ITEM, QTDA 
  INTO @IDITEM, @QTD
  FROM VENDAS_ITENS 
  WHERE VENDAS_ITENS.ID_PAI = OLD.ID;       

  BEGIN
    UPDATE PRODUTOS_DADOS
    SET STQ_ATUAL = STQ_ATUAL + @QTD
    WHERE ID = @IDITEM;
  END;              
END IF;

Plus this trigger only refreshes when you exite only one item in the items table, if you have more than one the following error "Result consisted of more than one row"

    
asked by anonymous 08.02.2018 / 15:27

0 answers