
ALTER TRIGGER [dbo].[TRG_RC_VD_CONV_VENCTO] ON [dbo].[RC_VD_CONV] 
--FOR INSERT,UPDATE
FOR INSERT
AS
	UPDATE 
		v
	SET
		v.DT_FECHA = CONVERT(CHAR(10),DATEADD(MONTH, v.PARC-1, DATEADD(day, QTDE_VENCTO, i.DT_VD)),120)
	FROM         
		INSERTED i INNER JOIN RC_VD_CONV v ON
		i.CD_EMP = v.CD_EMP AND
		i.CD_CTR = v.CD_CTR		
		INNER JOIN RC_CLI_CONV_RC_CLI ON 
		i.CD_EMP = RC_CLI_CONV_RC_CLI.CD_EMP AND 
		i.CD_CLI = RC_CLI_CONV_RC_CLI.CD_CLI 
		INNER JOIN RC_CLI_CONV ON 
		RC_CLI_CONV_RC_CLI.CD_EMP = RC_CLI_CONV.CD_EMP AND 
		RC_CLI_CONV_RC_CLI.CD_CONV = RC_CLI_CONV.CD_CONV
	WHERE
		RC_CLI_CONV.TP_FECHAMENTO = 1