
IF EXISTS (SELECT * FROM SYS.TRIGGERS WHERE NAME = 'TRG_TELE_ORC_ETAPA_EST_PED_VD_EXCLUI_PENDENCIA')
begin
	DROP TRIGGER [dbo].[TRG_TELE_ORC_ETAPA_EST_PED_VD_EXCLUI_PENDENCIA]
end
go

CREATE TRIGGER [dbo].[TRG_TELE_ORC_ETAPA_EST_PED_VD_EXCLUI_PENDENCIA] ON [dbo].[TELE_ORC_EST_PED_VD]
FOR INSERT, UPDATE
AS
    --Exclui pendencia do pedido do televendas
     DELETE FROM p
     FROM 
	   TELE_ORC_PENDENCIA p
	   join INSERTED i on 
	   i.CD_ORC = p.CD_ORC;

GO


