Creation of Trigger for INSERT in another table in IBexpert

0

Good morning, I had the need to create a stock control, but I had never used a trigger.

I have 3 tables COMPRA ABASTECIMENTO and MOVIMENTO_ESTOQUE

Table MOVIMENTO_ESTOQUE :

I would like that when I make a purchase I would write all the data except the COD_ABASTECIMENTO and the TIPO I would write a C credit and when I make a purchase all the data except COD_COMPRA and% COD_ITEMCOMPRA and TIPO was written D of debit, how would I create this trigger to control the stock?

    
asked by anonymous 15.02.2016 / 12:07

1 answer

0

I'm assuming the fields' names are the same, and left them empty in code because if you use a counter, then you can call them. With this you should be able to do for the supplies as well.

CREATE TRIGGER bi_movcompra for COMPRA
  BEFORE INSERT
AS
BEGIN
  INSERT INTO MOVIMENTO_ESTOQUE(CODIGO, DATA, COD_TANQUE, COD_PRODUTO, QUANTIDADE, TIPO, COD_COMPRA, COD_ITEMCOMPRA) VALUES(<COD>, NEW.DATA, NEW.COD_TANQUE, NEW.COD_PRODUTO, NEW.QUANTIDADE, 'C', NEW.COD_COMPRA, NEW.COD_ITEMCOMPRA)
END
    
15.02.2016 / 13:21