3

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

2 Answers 2

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

Replace and Lower should do the job here.

UPDATE dbo.User SET username = 'ACCOUNTS\' + LOWER(REPLACE(username, 'ACCOUNTS\', ''))
1
  • I added a filter because it wasn't clear to me that every single row in the table would begin with ACCOUNTS (I also skipped REPLACE()). Commented Jun 7, 2016 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.