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

CREATE TRIGGER [dbo].[TRG_EST_NFE_SOLIC_APROP_CRED_BENS_SERVS_PEND ] ON [dbo].[EST_NFE_SOLIC_APROP_CRED_BENS_SERVS] FOR INSERT AS

--Pendência de emissao de carta de correcao
INSERT INTO EST_NFE_SOLIC_APROP_CRED_BENS_SERVS_PEND (CD_CTR_SOLIC_APROP_CRED_BENS_SERVS    , DT_CAD, PEND_SOLUC)
	SELECT 
		t.CD_CTR_SOLIC_APROP_CRED_BENS_SERVS    , 
		GETDATE(),
		0
    FROM 
    	INSERTED t 
	WHERE 				
		NOT EXISTS (SELECT 
						pend.CD_CTR_SOLIC_APROP_CRED_BENS_SERVS     
					FROM 
						EST_NFE_SOLIC_APROP_CRED_BENS_SERVS_PEND pend
					WHERE 
						t.CD_CTR_SOLIC_APROP_CRED_BENS_SERVS     = pend.CD_CTR_SOLIC_APROP_CRED_BENS_SERVS    );



