0

I got a question asking- Write a Query to print the word 'beautiful vintage', but capitalising the first letter in each word, in mysql.

I googled and got suggestion from stack overflow using sub string combination with upper

So I tried :

Select CONCAT(UPPER(SUBSTRING('beautiful vintage',1,1)),LOWER(SUBSTRING('beautiful vintage',2))) as dd;

o/p ---> Beautiful vintage (where v is not getting converted)

Yet I could only capitalize the first word and couldn't the second word.

Please help me out with this one,thanks.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
  • in UPPER(SUBSTRING('beautiful vintage',1,1) only the first character is converted to uppercase and then the remainder is all set to lowercase : LOWER(SUBSTRING('beautiful vintage',2))) – Loïc Noest Mar 02 '20 at 09:35
  • Do you want to capitalise the first letter of each word, or do you want camel case? – Strawberry Mar 02 '20 at 09:49
  • yeah thanks, what changes should i make for the vintage first letter "v" also to be capitalized. – Mooventh Chiyan Mar 02 '20 at 09:50
  • @Strawberry I want to capitalise the first letter of each word – Mooventh Chiyan Mar 02 '20 at 09:51
  • You must divide your value to separate words (saving their order), capitalise 1st char in each word, then join the value back. If your value does not contain commas then using JSON_TABLE() may give the most simple query code it seems (and nevertheless it will be complex enough). – Akina Mar 02 '20 at 09:59
  • thanks @Akina, I'll give a try but what in case if its for a series of words. "Select Inticap(' beatiful vintage')" will that work on Mysql. – Mooventh Chiyan Mar 02 '20 at 15:38
  • It is possible in any case when exists some algorithm which allows to understand what is "word". – Akina Mar 02 '20 at 16:24
  • What is the maximum word count? If you have a fixed maximum word count it might be easier to do... I think – FanoFN Mar 03 '20 at 01:25
  • Does this help? https://stackoverflow.com/q/3278207/2430549 "MySQL - Capitalize first letter of each word, in existing table" – HoldOffHunger Mar 07 '20 at 19:04

0 Answers0