I have a function that is for changing text into proper case.

```
CREATE FUNCTION `fpropercasetest` (p_Value VARCHAR(8000))
RETURNS VARCHAR(8000)
BEGIN
DECLARE v_i INT; -- counter
DECLARE v_ProperCaseText VARCHAR(5000);
DECLARE v_Word VARCHAR(1000);
DECLARE v_isWhiteSpace TINYINT(1);
DECLARE v_c CHAR(1);

SET v_Word = '';
SET v_i = 1;
SET v_isWhiteSpace = 1;
SET v_ProperCaseText = '';

SET p_Value = LOWER(p_Value);

WHILE (v_i <= LENGTH(p_Value)+1) DO

    SET v_c = SUBSTRING(p_Value,v_i,1);

    IF v_isWhiteSpace = 1 THEN SET v_c = UPPER(v_c); END IF;

    SET v_isWhiteSpace = CASE WHEN (ASCII(v_c) BETWEEN 48 AND 58) THEN 0
                                    WHEN (ASCII(v_c) BETWEEN 64 AND 90) THEN 0
                                    WHEN (ASCII(v_c) BETWEEN 96 AND 123) THEN 0
                                    ELSE 1 END;

    IF v_isWhiteSpace = 0 THEN
        SET v_Word = CONCAT(v_Word, v_c);
    ELSE
        SET v_ProperCaseText = CONCAT(v_ProperCaseText, v_Word, v_c);
        SET v_Word = '';
    END IF;
    SET v_i = v_i + 1;
END WHILE;
return v_ProperCaseText;
END;

```

You can test with the following

```
SELECT fpropercasetest("this is just some text for you to test with");

```

When I entered any text with spaces I noticed that it just didn't register (e.g. with the text "this is some text" it would return "ThisIsSomeText" and it should return "This Is Some Text")

I debugged it with Visual Studio and noticed that substring was just ignoring spaces completely, it returns an empty string.

I'm completely stumped by this, any help will be greatly appreciated. Thanks.