Home Forums SQL Server 2008 T-SQL (SS2K8) Get all the domain and SQL users from an instance, per database RE: Get all the domain and SQL users from an instance, per database

  • you have to qualify the database in the query with a ?. you can also load the result into a table to make them searchable

    CREATE TABLE #tmp(dbname VARCHAR(256),username VARCHAR(256))

    INSERT #tmp EXEC sp_MSforeachdb 'select ''?'',name

    from [?].sys.database_principals

    where type in (''S'',''G'',''U'')

    and name not in (''dbo'',''guest'',''sys'',''INFORMATION_SCHEMA'',''##MS_PolicyEventProcessingLogin##'')'

    SELECT *

    FROM #tmp

    Bob
    -----------------------------------------------------------------------------
    How to post to get the best help[/url]