Splitting Domain from Domain\Username - With Multilanguage support ( Japanese, Dutch ... etc)

  • Hi,

    I need to Split Domain from (Domain\Username), and inset domain value in a new column. But character (' \ ') will be different in other languages like Japanese, Dutch ... etc.
    How can we write a generalized query that will work for any locale / collation.

    Below SQL Query will work for English usernames

    UPDATE UserProfiles SET Domain = SUBSTRING(username, 1, CHARINDEX('\', username) - 1) where username like '%\%'

    Also it Should work on Database : SQL SERVER 2008 R2, 2012, 2014, 2016 & 2017

    Please share your thoughts

    Thanks
    Rajesh Nair

  • You must use Unicode literal:

    N'/' instead of '/'.

    I assume, all columns and variables are defined as nvarchar, not varchar.

    _____________
    Code for TallyGenerator

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply