
IF EXISTS(SELECT * FROM SYS.TRIGGERS WHERE OBJECT_ID=OBJECT_ID(N'[DBO].[TRG_EST_PROD_TRANSF_STS_TRANSF]') )
	DROP TRIGGER  TRG_EST_PROD_TRANSF_STS_TRANSF;
GO

CREATE TRIGGER  TRG_EST_PROD_TRANSF_STS_TRANSF ON EST_PROD_TRANSF
FOR UPDATE
AS 
IF UPDATE (STS_TRANSF)  
BEGIN 
	DELETE FROM EST_WMS_SAI_PEND
	  FROM INSERTED EST_PROD_TRANSF
		   JOIN EST_PROD_TRANSF_EST_WMS_SAI ON EST_PROD_TRANSF_EST_WMS_SAI.CD_EMP    = EST_PROD_TRANSF.CD_EMP
										   AND EST_PROD_TRANSF_EST_WMS_SAI.CD_FILIAL = EST_PROD_TRANSF.CD_FILIAL
										   AND EST_PROD_TRANSF_EST_WMS_SAI.CD_CTR    = EST_PROD_TRANSF.CD_CTR
		   JOIN EST_WMS_SAI_PEND ON EST_PROD_TRANSF_EST_WMS_SAI.CD_PED_WMS = EST_WMS_SAI_PEND.CD_PED_WMS
		   
	 WHERE EST_PROD_TRANSF.STS_TRANSF = 4

END 