IF NOT OBJECT_ID('TRG_EST_NF_ENT_CANCEL_PEND') IS NULL
	BEGIN 
		DROP TRIGGER TRG_EST_NF_ENT_CANCEL_PEND
	END

GO

------------------------------------INSERO EM EST_NF_ENT_NFE_PEND------------------------------------      
CREATE TRIGGER [dbo].[TRG_EST_NF_ENT_CANCEL_PEND] ON [dbo].[EST_NF_ENT_NFE_CANCEL] FOR INSERT AS      

begin      
	
	IF EXISTS (SELECT P.CD_EMP 
			   FROM EST_NF_ENT_CANCEL_SOLIC P
					INNER JOIN inserted I ON 
						P.CD_EMP		= I.CD_EMP
						AND P.CD_FILIAL = I.CD_FILIAL 
						AND P.CD_NF		= I.CD_NF)		
		BEGIN 
			INSERT INTO EST_NF_ENT_CANCEL_PEND (CD_EMP, CD_FILIAL, CD_NF, DT_CAD)
				SELECT 
					I.CD_EMP, I.CD_FILIAL, I.CD_NF, GETDATE()
				FROM INSERTED I
		END
	 
end

GO


