IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[sp_fco_upd_diagnosticos]') 
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   DROP PROCEDURE dbo.sp_fco_upd_diagnosticos
GO
CREATE PROCEDURE dbo.sp_fco_upd_diagnosticos
(
    @pvc_diagnostico varchar(5),
    @pvc_descripcion varchar(255)
)
AS
    DECLARE @vti_existe tinyint
BEGIN

    SET @vti_existe = 0


    SELECT @vti_existe = 1 
    FROM fco_diagnosticos
    WHERE diagnostico = @pvc_diagnostico

    IF @vti_existe = 1 
        UPDATE fco_diagnosticos 
        SET descripcion = @pvc_descripcion
        WHERE diagnostico = @pvc_diagnostico
    ELSE
        INSERT INTO fco_diagnosticos (diagnostico, descripcion)
        VALUES (@pvc_diagnostico, @pvc_descripcion)
END

GO
GRANT EXECUTE ON sp_fco_upd_diagnosticos TO Public
GO