IF NOT OBJECT_ID('TRG_EST_NF_ENT_DANFE_PROVISORIO_SUSPENSO_INCLUI_PEDENCIA') IS NULL
	BEGIN 
		DROP TRIGGER TRG_EST_NF_ENT_DANFE_PROVISORIO_SUSPENSO_INCLUI_PEDENCIA  
	END
GO	
CREATE TRIGGER [dbo].[TRG_EST_NF_ENT_DANFE_PROVISORIO_SUSPENSO_INCLUI_PEDENCIA] ON [dbo].[EST_NF_ENT_DANFE_PROVISORIO_SUSPENSO] FOR  DELETE AS
BEGIN
	---------------------------------------------------------------------------
	--Incluindo Pedencia de arquivo DANFE
	---------------------------------------------------------------------------
	INSERT INTO EST_NF_ENT_DANFE_PROVISORIO_PENDENTE (CD_CTR, DT_CAD,PRE_ENTRADA)
	SELECT
		D.CD_CTR,
		getdate() DT_CAD,
		0
	FROM 
		DELETED D
		LEFT OUTER JOIN EST_NF_ENT_DANFE_PROVISORIO_PENDENTE W ON 
		D.CD_CTR = W.CD_CTR
	WHERE
		W.CD_CTR IS NULL
END


