-- Script 1: this shows a list of users and the number of reports to them
--
SELECT DISTINCT POA_Report_To_User_ID
        
,COUNT(POA_Report_To_User_ID) AS 'Reports'
FROM DYNAMICS..POA40002
WHERE POA_Report_To_User_ID <> ''
GROUP BY POA_Report_To_User_ID
ORDER BY Reports DESC

-- Script 2: this shows a list of users, to whom they report, and their limit
--
SELECT INTERID
        
,APRVLUSERID
        
,POA_Report_To_User_ID
        
,POA_Approval_Authority_A
        
,CASE 
                
WHEN POA_Security_Type = 1
                        
THEN 'ANY'
                
ELSE 'RESTRICTED'
                
END AS 'ApprType'
FROM DYNAMICS..POA40002 A
INNER JOIN DYNAMICS..SY01500 B ON A.CMPANYID = B.CMPANYID
WHERE POA_Approval_Authority_A <> 0
ORDER BY INTERID
        
,APRVLUSERID