• It might not be the optimal way, but it's simple enough for everyone to understand. However, I haven't tested for performance against other methods.

    DECLARE @test-2Table(

    MyStringvarchar(MAX))

    INSERT @test-2 VALUES

    ('NT AUTHORITY\SYSTEM: [System Admin]YES;[Security Admin];[Server Admin]YES;[setup Admin];[Process Admin];[Disk Admin];[Database Creator]'),

    ('NT SERVICE\MSSQL$instance1: [System Admin]YES;[Security Admin];[Server Admin];[setup Admin];[Process Admin];[Disk Admin];[Database Creator]'),

    ('NT SERVICE\SQLAGENT$instance1: [System Admin]YES;[Security Admin];[Server Admin];[setup Admin];[Process Admin];[Disk Admin];[Database Creator]YES')

    SELECT LEFT( MyString, CHARINDEX( ':', MyString) + 1) +

    CASE WHEN CHARINDEX( 'System Admin]YES;', MyString) > 0

    THEN '[System Admin]YES;' ELSE '' END +

    CASE WHEN CHARINDEX( 'Security Admin]YES;', MyString) > 0

    THEN '[Security Admin]YES;' ELSE '' END +

    CASE WHEN CHARINDEX( 'Server Admin]YES;', MyString) > 0

    THEN '[Server Admin]YES;' ELSE '' END +

    CASE WHEN CHARINDEX( 'setup Admin]YES;', MyString) > 0

    THEN '[setup Admin]YES;' ELSE '' END +

    CASE WHEN CHARINDEX( 'Process Admin]YES;', MyString) > 0

    THEN '[Process Admin]YES;' ELSE '' END +

    CASE WHEN CHARINDEX( 'Disk Admin]YES;', MyString) > 0

    THEN '[Disk Admin]YES;' ELSE '' END +

    CASE WHEN CHARINDEX( 'Database Creator]YES', MyString) > 0

    THEN '[Database Creator]YES;' ELSE '' END

    FROM @test-2

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2