Sql-server – Alter the letters after “ACCOUNTS\” to lower case

sql servert-sqlupdate

I have a database table, users, with different username cases (see the example). How can I update the letters after ACCOUNTS\ to lower case?

ACCOUNTS\James.McAvoy
ACCOUNTS\michael.fassbender
ACCOUNTS\nicholas.hoult
ACCOUNTS\Oscar.Isaac

Desired result after the update:

ACCOUNTS\james.mcavoy
ACCOUNTS\michael.fassbender
ACCOUNTS\nicholas.hoult
ACCOUNTS\oscar.isaac

Best Answer

UPDATE dbo.[User]
SET username_column = N'ACCOUNTS' + LOWER(SUBSTRING(username_column, 9, 4000))
WHERE username_column LIKE 'ACCOUNTS\%';