baniol
5/9/2013 - 1:37 PM

mysql split username, string

mysql split username, string

-- Splits username by first space, shortens first name to the first letter & adds a dot. Ex.: Jonh Smith -> J. Smith

SELECT CONCAT(CONCAT(LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX( `username` , ' ', 2 ),' ',1),1),"",". ") ," ", SUBSTRING_INDEX(SUBSTRING_INDEX( `username` , ' ', -1 ),' ',2)) AS user
FROM tbl_name