IF EXISTS(SELECT * FROM SYS.TRIGGERS WHERE NAME = 'TRG_RC_DEB_ENVIO_RESPOSTA_GRAVA_ERRO')
BEGIN
    DROP TRIGGER TRG_RC_DEB_ENVIO_RESPOSTA_GRAVA_ERRO;
END;
GO

    CREATE TRIGGER TRG_RC_DEB_ENVIO_RESPOSTA_GRAVA_ERRO ON RC_DEB_ENVIO_RESPOSTA FOR INSERT, UPDATE
AS
BEGIN
    INSERT INTO RC_DEB_ENVIO_RESPOSTA_ERRO
                (CD_EMP,
                 CD_FILIAL,
                 CD_RC_DEB
                )
    
    SELECT CD_EMP,
           CD_FILIAL,
           CD_RC_DEB

    FROM INSERTED
     
    WHERE STATUS <> 0;
END;
