A
A
Arslanali2017-07-25 14:27:51
MySQL
Arslanali, 2017-07-25 14:27:51

How to reformat a string to SURNAME_IO?

Hello colleagues.
There was a problem.
There is a line Surname Name Patronymic how to translate to the form SURNAME_IO using sql?

SELECT REPLACE(UPPER(usersid), ' ', '_') as m FROM applications

Did it beforehand.
Need to use regular expressions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2017-07-25
@Arsen2011

concat_ws(
   "_", 
   last_name, 
   concat_ws(
      "", 
      (select LEFT(firstname, 1) from applications), 
      (select LEFT(middlename, 1) from applications)
   )
)

CONCAT_WS
LEFT

A
Arslanali, 2017-07-25
@Arsen2011

SELECT [ROW_ID]
      ,[ФИО]	
    ,upper(SUBSTRING (([ФИО]),1,CHARINDEX(' ',[ФИО])-1)+'_'+SUBSTRING (([ФИО]),CHARINDEX(' ',[ФИО])+1,1) +''+
    SUBSTRING (([ФИО]),(CHARINDEX(' ',[ФИО])+CHARINDEX(' ',SUBSTRING (([ФИО]),CHARINDEX(' ',[ФИО])+1,100)))+1,1))
   
  FROM [Карточки регистрации] k
  where k.[ROW_ID] in (908,247,809)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question