Start SQL string in uppercase
Solved
t671
Posted messages
1475
Registration date
Status
Member
Last intervention
-
t671 Posted messages 1475 Registration date Status Member Last intervention -
t671 Posted messages 1475 Registration date Status Member Last intervention -
Hello,
I have a string of characters, composed of one or more words.
I would like the first letter of each word to be in uppercase, and the rest of each word in lowercase.
I know if there is only one word, but several ......
Thank you.
I have a string of characters, composed of one or more words.
I would like the first letter of each word to be in uppercase, and the rest of each word in lowercase.
I know if there is only one word, but several ......
Thank you.
2 answers
Hi,
why in SQL? wouldn't it be better to do this during insertion?
SQL is a low-level language (simple) you won't have functions like regular expressions and string slicing is more difficult than with a higher-level language.
In PHP you can use explode to split each word into an array
http://www.php.net/manual/fr/function.explode.php
Then take the first letter of each word and capitalize it and the remaining letters in lowercase with strtoupper / strtolower
http://php.net/manual/fr/function.strtoupper.php
Then concatenate the string again, remembering to add a space between each word.
Is that clear?
Can you use PHP? If so, it’s pretty simple to add to your function the retrieval of data already stored in the tables to “normalize” them according to your syntax.
Another solution that is probably just as good is not to consider uppercase and lowercase in the tables but only when displaying, basically you run a query and apply the capitalization at the start of each word for every result.
why in SQL? wouldn't it be better to do this during insertion?
SQL is a low-level language (simple) you won't have functions like regular expressions and string slicing is more difficult than with a higher-level language.
In PHP you can use explode to split each word into an array
http://www.php.net/manual/fr/function.explode.php
Then take the first letter of each word and capitalize it and the remaining letters in lowercase with strtoupper / strtolower
http://php.net/manual/fr/function.strtoupper.php
Then concatenate the string again, remembering to add a space between each word.
Is that clear?
Can you use PHP? If so, it’s pretty simple to add to your function the retrieval of data already stored in the tables to “normalize” them according to your syntax.
Another solution that is probably just as good is not to consider uppercase and lowercase in the tables but only when displaying, basically you run a query and apply the capitalization at the start of each word for every result.
Thank you
See you soon