/****** Object:  Trigger [TRG_EST_NF_SAI_LOTE_ENVIO_WMS_INCLUI_PENDENCIA]  ******/
IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_EST_NF_SAI_LOTE_ENVIO_WMS_INCLUI_PENDENCIA]'))
DROP TRIGGER [dbo].[TRG_EST_NF_SAI_LOTE_ENVIO_WMS_INCLUI_PENDENCIA]
GO
GO
-------------------------------------INSIRO EM EST_NF_SAI_LOTE_ENVIO_WMS--------------------------------------
CREATE TRIGGER [dbo].[TRG_EST_NF_SAI_LOTE_ENVIO_WMS_INCLUI_PENDENCIA] ON [dbo].[EST_NF_SAI_LOTE_ENVIO_WMS] FOR INSERT AS

INSERT INTO EST_NF_SAI_LOTE_ENVIO_WMS_PENDENTE (   
	CD_CTR, 
	DT_CAD)
    SELECT 
		CD_CTR, 
		GETDATE()
    FROM 
		INSERTED s
    WHERE 
	   	NOT EXISTS (SELECT 
						* 
					  FROM 
						EST_NF_SAI_LOTE_ENVIO_WMS_PENDENTE p 
					  WHERE 
						p.CD_CTR=s.CD_CTR );

GO

ALTER TABLE [dbo].[EST_NF_SAI_LOTE_ENVIO_WMS] ENABLE TRIGGER [TRG_EST_NF_SAI_LOTE_ENVIO_WMS_INCLUI_PENDENCIA]
