IF OBJECT_ID('dbo.fn_ape1') IS NOT NULL
    DROP FUNCTION dbo.fn_ape1
GO
CREATE FUNCTION dbo.fn_ape1
(
    @pvc_nombre varchar(100)
)
RETURNS varchar(30)
AS
BEGIN
DECLARE
    @vti_pos1 tinyint,
    @pvc_cad varchar(30)

    SET @vti_pos1 = CharIndex('/', @pvc_nombre)
    IF @vti_pos1 = 0
        SET @pvc_cad = @pvc_nombre
    ELSE
        SET @pvc_cad = SubString(@pvc_nombre, 1, @vti_pos1 - 1)

    SET @pvc_cad = UPPER(Left(@pvc_cad, 1)) + LOWER(SubString(@pvc_cad, 2, 29))
    
    RETURN (@pvc_cad)
END
GO
GRANT EXECUTE ON fn_ape1 TO PUBLIC
GO
