In PHP we would use UCFIRST, so how do we do this in MySQL?

SELECT CONCAT(UPPER(SUBSTRING(firstName, 1, 1)), LOWER(SUBSTRING(firstName FROM 2))) AS properFirstName

You could also create your own MySQL function of this and then just call it, instead of writing it in selects all the time:

CREATE FUNCTION initCap (s varchar(255))

RETURNS VARCHAR(255) DETERMINISTIC

RETURN CONCAT(UPPER(LEFT(s,1)),MID(s,2));

How to set text to have a Capital letter and then lowercase letters
Tagged on:

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

eighty − = seventy three