ALTER PROCEDURE [dbo].[P_ATUALIZA_ST_RC_VD_CONV_NCC] (@CD_EMP INT ,@CD_CTR INT)
AS


DECLARE @VLR_CREDITOS MONEY

BEGIN

	SET @VLR_CREDITOS = (SELECT SUM(VLR_CRED) FROM RC_VD_CONV_CRED WHERE CD_EMP=@CD_EMP AND CD_CTR=@CD_CTR)

	-- update status
	UPDATE RC_VD_CONV SET
		ST_FECHVD_CONV = (CASE  WHEN VLR_CONV = @VLR_CREDITOS THEN 3 
				  ELSE ST_FECHVD_CONV END)

	WHERE RC_VD_CONV.CD_EMP = @CD_EMP
		  AND RC_VD_CONV.CD_CTR = @CD_CTR
	
END

