IF  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[P_REMOVE_DESC_PONTUAL_RC_DEB]') AND TYPE IN (N'P', N'PC'))
DROP PROCEDURE [DBO].[P_REMOVE_DESC_PONTUAL_RC_DEB]
GO
GO
CREATE PROCEDURE P_REMOVE_DESC_PONTUAL_RC_DEB
WITH ENCRYPTION 
AS
UPDATE D
SET
	VLR_DESC=0
FROM   
	RC_CREDIARIO_FECHA F
	INNER JOIN RC_CREDIARIO_FECHA_RC_DEB R ON 
	F.CD_EMP		= R.CD_EMP		AND
	F.CD_CTR_FECHA	= R.CD_CTR_FECHA

	INNER JOIN RC_DEB D ON 
	R.CD_EMP =D.CD_EMP AND
	R.CD_FILIAL =D.CD_FILIAL AND
	R.CD_RC_DEB =D.CD_RC_DEB 
WHERE
	D.CD_EMP=1
	AND F.PERC_DESC_PONTUAL>0 
	AND D.STS_DP=0
	AND D.VLR_DESC >0
	AND D.DT_VENCTO < convert(date,GETDATE());