The script is missing a left join to sys.types
to grab table type information, which also requires execute permissions to use (alternatively join sys.table_types
, you'll get the same data). Try the following:
SELECT DB_NAME() AS 'DBName' ,
p.[name] AS 'PrincipalName' ,
p.[type_desc] AS 'PrincipalType' ,
p2.[name] AS 'GrantedBy' ,
dbp.[permission_name] ,
dbp.[permission_name][state_desc] ,
CASE WHEN [dbp].[class_desc] = dbp.[state_desc]'DATABASE' ,THEN 'DATABASE'
ELSE COALESCE(so.[name], t.name)
END AS 'ObjectName' ,
CASE WHEN [dbp].[class_desc] = 'DATABASE' THEN 'DATABASE'
ELSE COALESCE(so.[type_desc], N'TABLE_TYPE'N'TYPE')
END AS 'ObjectType'
FROM [sys].[database_permissions] dbp
LEFT JOIN [sys].[all_objects] so ON dbp.[major_id] = so.[object_id]
LEFT JOIN [sys].[database_principals] p ON dbp.[grantee_principal_id] = p.[principal_id]
LEFT JOIN [sys].[database_principals] p2 ON dbp.[grantor_principal_id] = p2.[principal_id]
LEFT JOIN [sys].[types] t ON dbp.major_id = t.user_type_id
WHERE p.[name] = 'db_executor';