/****** Object:  Trigger [TRG_EST_WMS_SAI_RET_PEND_INCLUI]    Script Date: 04/02/2015 14:44:49 ******/
IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_EST_WMS_SAI_RET_PEND_INCLUI]'))
DROP TRIGGER [dbo].[TRG_EST_WMS_SAI_RET_PEND_INCLUI]
GO
GO
GO
CREATE TRIGGER [dbo].[TRG_EST_WMS_SAI_RET_PEND_INCLUI] ON [dbo].[EST_WMS_SAI_RET] FOR INSERT AS
	BEGIN
		INSERT INTO EST_WMS_SAI_RET_PEND
		SELECT i.CD_PED_WMS, GETDATE()
		FROM INSERTED i
		WHERE NOT EXISTS (SELECT CD_PED_WMS 
						  FROM EST_WMS_SAI_RET_PEND p
						  WHERE p.CD_PED_WMS = i.CD_PED_WMS)		
	END
GO


