Saturday, 20 May 2017

sql - How to lowercase the whole string keeping the first in uppercase in MYSQL





My Table column -



enter image description here



My expected Output to change in column -




Smith, Allen, Doyle, Dennis, Baker, Waker


This is what i tried, but not working :( -



UPDATE TABLE `employee`
SET last_name = UCASE(LEFT(lower(last_name), 1))

UPDATE TABLE `employee`
SET last_name = ucase(lower(last_name),1)



Followed this link too - Resource



ERROR --



#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE `employee` SET last_name = UCASE(LEFT(lower(last_name), 1))' at line 1


Let me know what I am doing wrong and how to fix.



Answer



TABLE is a reserved keyword. It should be escaped with backtick.



I think TABLE should not be in your query, (i think it is a typo)



UPDATE employee
SET last_Name = CONCAT(UCASE(LEFT(last_Name, 1)), LCASE(SUBSTRING(last_Name, 2)))




No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...