IF EXISTS (
SELECT *
FROM sys.database_principals
WHERE name = 'role_a'
and type = 'R'
)
BEGIN -- Role_A exists, add to role
ALTER ROLE [role_a] ADD MEMBER [Domain/SqlAgent]
END
ELSE IF EXISTS (
SELECT *
FROM sys.database_principals
WHERE name = 'role_b'
and type = 'R'
)
BEGIN -- Role_B exists, add to role
ALTER ROLE [role_b] ADD MEMBER [Domain/SqlAgent]
END