Query to show users of Organization Roles for each account (MSSQL & PGSQL)

Query to show users of Organization Roles for each account (MSSQL & PGSQL)

T
ested in Build PGSQL (14300) or MSSQL (14306)

select ad.org_name "Account Name", org.orgrolename "ORG Role Name", aau.first_name "User" from orgroles org left join roletousermapping rtu ON org.orgroleid=rtu.roleid LEFT JOIN roletouseraccountmapping rum ON rtu.rumid=rum.rumid LEFT JOIN sduser sdu ON rtu.userid=sdu.userid LEFT JOIN aaauser aau ON sdu.userid=aau.user_id LEFT JOIN accountdefinition ad ON rum.accountid=ad.org_id WHERE ORGROLENAME='$AM_(ACCOUNT_MANAGER)$' OR ORGROLENAME='$SDM_(SERVICE_DELIVERY_MANAGER)$' AND sdu.status='ACTIVE' 
group by ad.org_name,  org.orgrolename, aau.first_name ORDER BY org.orgrolename

                  New to ADSelfService Plus?