--Query
SELECT UserInfo.[Name],
ElementName AS [Report Name],
UserInfo.[Enable] AS [Active Employee]
INTO #temp
FROM SysLastValue WITH(NOLOCK)
INNER JOIN UserInfo WITH(NOLOCK)
ON UserInfo.ID = SysLastValue.UserID
WHERE UserID NOT IN ('Admin', '')
AND RecordType = 18 /* Report */
SELECT t.[Report Name],
(SELECT COUNT(DISTINCT [Name])
FROM #temp sub
WHERE sub.[Active Employee] = 1
AND sub.[End User] = 1
AND sub.[Report Name] = t.[Report Name]) AS [# of Active Employees Who Ran The Report]
FROM #temp t
GROUP BY t.[Report Name]
ORDER BY t.[Report Name]
DROP TABLE #temp
SELECT UserInfo.[Name],
ElementName AS [Report Name],
UserInfo.[Enable] AS [Active Employee]
INTO #temp
FROM SysLastValue WITH(NOLOCK)
INNER JOIN UserInfo WITH(NOLOCK)
ON UserInfo.ID = SysLastValue.UserID
WHERE UserID NOT IN ('Admin', '')
AND RecordType = 18 /* Report */
SELECT t.[Report Name],
(SELECT COUNT(DISTINCT [Name])
FROM #temp sub
WHERE sub.[Active Employee] = 1
AND sub.[End User] = 1
AND sub.[Report Name] = t.[Report Name]) AS [# of Active Employees Who Ran The Report]
FROM #temp t
GROUP BY t.[Report Name]
ORDER BY t.[Report Name]
DROP TABLE #temp
No comments:
Post a Comment