I have a query that gets me the number of total folders scanned for the current day and I need to add a column that also totals the number of tracking numbers for each person.
Here is the current query
Getting great performance from this query thanks to gmmastros taking the time to explain indexing in an understandable manner.
THANKS George!!!!
Thanks
John Fuhrman
Here is the current query
Code:
With cte_TodaysRecords(EmployeeFullName, BoxNumber, FileNumber, TrackingDate)
As (
SELECT
EmployeeFullName = Case
When e.EmployeeMI = '' Then e.EmployeeLN + ', ' + e.EmployeeFN
When e.EmployeeMI Is Null Then e.EmployeeLN + ', ' + e.EmployeeFN
When e.EmployeeMI <> '' Then e.EmployeeLN + ', ' + e.EmployeeFN + ' ' + e.EmployeeMI
End,
a.BoxNumber As [Tracking Number],
a.FileNumber As [File Number],
a.TrackingDate As [Tracking Date and Time]
FROM dbo.tblTrackingTable a
INNER JOIN dbo.tblEmployee e ON a.EmployeeID = e.EmployeeID
WHERE (a.TrackingDate
BETWEEN DATEADD(dd, DATEDIFF(dd, 0, CURRENT_TIMESTAMP), 0)
AND DATEADD(ss, - 1, DATEADD(dd, DATEDIFF(dd, 0, CURRENT_TIMESTAMP), 1)))
AND (a.EmployeeID IS NOT NULL)
AND (a.FileNumber <> '')
AND (a.BoxNumber <> '')
AND (a.FileNumber <> '.BOX.END.')
AND (a.TrackingDate IS NOT NULL)
),
cte_Rollup(EmployeeFullName, [Total Folders Scanned])
As (
Select
EmployeeFullName,
Count(FileNumber) As [Total Folders Scanned]
From cte_TodaysRecords
Group By EmployeeFullName
with Rollup)
Select * From cte_Rollup Where EmployeeFullName Is Not Null
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 1 ms.
SQL Server parse and compile time:
CPU time = 79 ms, elapsed time = 91 ms.
SQL Server Execution Times:
CPU time = 296 ms, elapsed time = 285 ms.
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 1 ms.
6,798,298 Total Rows in Table dbo.tblTrackingTable
Getting great performance from this query thanks to gmmastros taking the time to explain indexing in an understandable manner.
THANKS George!!!!
Thanks
John Fuhrman