• with JustInD as (select name

    from sys.server_principals db

    where not exists (select 1 from master.sys.server_principals mp

    where db.name = mp.name)

    )

    This cte gives you the names that exist in sys.server_principals in your current database but not in the master. However it looks like you are wanting to walk through all the databases doing this. Add this to your code and plug in @DBName in your from clause.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills