IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_EST_PED_VD_ESP_VOL_MC_VOL]'))
	DROP TRIGGER [dbo].[TRG_EST_PED_VD_ESP_VOL_MC_VOL]
GO

CREATE TRIGGER TRG_EST_PED_VD_ESP_VOL_MC_VOL   ON EST_PED_VD
AFTER INSERT , UPDATE
AS
 	UPDATE V
	SET
		ESP_VOL = ISNULL(V.ESP_VOL, ''), 
		MC_VOL  = ISNULL(V.MC_VOL, '')
	FROM 
		INSERTED I 
		JOIN EST_PED_VD V ON 
		I.CD_EMP	=		V.CD_EMP	AND
		I.CD_FILIAL	=		V.CD_FILIAL	AND
		I.CD_PED	=		V.CD_PED	 
	WHERE
			V.CD_EMP=1
		AND V.CD_FILIAL = 903 
		AND (V.ESP_VOL IS NULL OR V.MC_VOL IS NULL)
GO
