IF NOT OBJECT_ID('TRG_CTB_EXP_CTR_PDV_CONSLD_VD_REPROCESSAR') IS NULL
	BEGIN 
		DROP TRIGGER TRG_CTB_EXP_CTR_PDV_CONSLD_VD_REPROCESSAR 
	END 
GO
CREATE TRIGGER [dbo].[TRG_CTB_EXP_CTR_PDV_CONSLD_VD_REPROCESSAR] ON [dbo].[CTB_EXP_CTR] 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_EXP

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


