In SQL Server how to convert string part uppercase based on the separator: \?

5

I need to make a script to convert all user records into a table in this format (single field):

INFORMATICA\desenvolvedor  
ADMINISTRACAO\contador

That is, before the uppercase bar and then the lower bar. How to do this in SQL Server?

Currently the records are like this (single field):

informatica\desenvolvedor ou  
INFORMATICA\DESENVOLVEDOR
    
asked by anonymous 17.12.2013 / 14:30

2 answers

8

I do not know if it's the most elegant solution, but take care of your case:

select Upper(Substring(t.texto, 0, CHARINDEX ( '\' ,t.texto) ) ) 
       + '\' + 
       lower(Substring(t.texto, CHARINDEX ( '\' ,t.texto) + 1, LEN(t.texto)) )
from (
    select 'administrador\edgar' as texto
) as t
    
17.12.2013 / 14:43
0

Below is a function created from the Edgar response, to only pass the string as a parameter.

CREATE FUNCTION FORMATAR_USUARIO(@STRING VARCHAR(1000)) RETURNS VARCHAR(1000)
BEGIN
    RETURN UPPER(SUBSTRING(@STRING, 0, CHARINDEX ( '\' ,@STRING) ) ) + '\' +    LOWER(SUBSTRING(@STRING, CHARINDEX ( '\' ,@STRING) + 1, LEN(@STRING)) )
END 

So, once the function is created, use it:

SELECT dbo.FORMATAR_USUARIO('uuuuu\oooooo')

Output:

UUUUU\oooooo
    
17.12.2013 / 16:08