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

CREATE TRIGGER   TRG_TELE_ORC_PAG_DINHEIRO_PENDENTE  ON TELE_ORC_PAG
FOR INSERT, UPDATE
AS
INSERT INTO TELE_ORC_PAG_DINHEIRO_PENDENTE (CD_ORC_PAG,DT_CAD)
SELECT    
    CD_ORC_PAG, GETDATE()
	FROM INSERTED
		INNER JOIN TELE_ORC ON Inserted.CD_ORC = TELE_ORC.CD_ORC AND TELE_ORC.CD_CX_RET IS NOT NULL
	WHERE CD_TIPO_PAG = 1