IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_EST_PROD_INTEGRACAO_ENVIO_PENDENTE_INCLUI_PENDENCIA]'))
DROP TRIGGER [dbo].[TRG_EST_PROD_INTEGRACAO_ENVIO_PENDENTE_INCLUI_PENDENCIA]
GO
GO
GO
-------------------------------------INSERO EM PDV_VD--------------------------------------
CREATE TRIGGER [dbo].[TRG_EST_PROD_INTEGRACAO_ENVIO_PENDENTE_INCLUI_PENDENCIA] ON [dbo].[EST_PROD] FOR INSERT AS

	INSERT INTO EST_PROD_INTEGRACAO_ENVIO_PENDENTE (CD_EMP, 
												CD_PROD,
												DT_CAD)
    SELECT DISTINCT 
		I.CD_EMP, 
		I.CD_PROD,
		GETDATE()
    FROM 
		INSERTED I
		LEFT JOIN EST_PROD_INTEGRACAO_ENVIO_PENDENTE P ON 
		I.CD_EMP = P.CD_EMP AND
		I.CD_PROD = P.CD_PROD
	WHERE
		P.CD_EMP IS NULL