Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a table with a column that looks like the below:

+----------------+
| name           |
+----------------+
| Tim^*^Abas     |
| Roy^*^Techs    |
| Amanda^*^Futer |
| ...            |
+----------------+

It corresponds to first name, last name, with three characters ^*^ joining them.

I want to change this table to abbreviate each name so it takes the first letter of each first name, last name. The final column might look like:

+----------------+
| name           |
+----------------+
| T.A.           |
| R.T.           |
| A.F.           |
| ...            |
+----------------+

Can this be done strictly in SQL?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
175 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is one option:

concat(left(name, 1), '.', substring(name, locate('^*^', name) + 3, 1), '.')

If you wanted an update query:

update mytable
set name = concat(left(name, 1), '.', substring(name, locate('^*^', name) + 3, 1), '.')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...