IF NOT OBJECT_ID('TRG_CTB_CONTROLE_EXPORTACAO_PDV_CONSLD_VD_REPROCESSAR') IS NULL
	BEGIN 
		DROP TRIGGER TRG_CTB_CONTROLE_EXPORTACAO_PDV_CONSLD_VD_REPROCESSAR 
	END 
GO
CREATE TRIGGER [dbo].[TRG_CTB_CONTROLE_EXPORTACAO_PDV_CONSLD_VD_REPROCESSAR] ON [dbo].[CTB_CONTROLE_EXPORTACAO] FOR  INSERT,UPDATE AS
BEGIN
	DELETE 
		c
	FROM 
		PDV_CONSLD_VD_MOVIMENTO_REPROCESSAR c INNER JOIN INSERTED i ON
		c.CD_EMP = i.CD_EMP AND
		c.CD_FILIAL = i.CD_FILIAL AND
		c.DT_MOV = i.DT_EXPORT

		INSERT INTO PDV_CONSLD_VD_MOVIMENTO_REPROCESSAR
		SELECT
			distinct
			i.CD_EMP,
			i.CD_FILIAL,
			i.DT_EXPORT,
			'EXPORTACAO CONTABIL',
			GETDATE()
		FROM
			INSERTED i 
		END


