• JeremyE (8/20/2012)


    This should do it

    CREATE TABLE #srvroles(ServerRole VARCHAR(20), Membername VARCHAR(200), MEMBERSID VARBINARY(MAX))

    GO

    INSERT #srvroles EXEC sp_helpsrvrolemember

    SELECT 'EXEC master..sp_addsrvrolemember @loginame = N'+''''+MemberName+''''+','+'@rolename = N'+''''+ServerRole+''''

    FROM #srvroles

    GO

    DROP TABLE #srvroles

    That will give you Fixed Server Role memberships. You'll also need to consult the sys.server_permissions System View to gain the complete picture.

    Edit: as a side note sp_addsrvrolemember was marked obsolete in SQL Server 2012 so if this code is going in your toolbox you may want to consider using ALTER SERVER ROLE instead on 2012 instances.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato