Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- A.EntryDate,
- COALESCE(B.AuditCount,0) AS AuditCount,
- COALESCE(B.TimerCount,0) AS AuditTimerCount,
- COALESCE(B.AvgTimer,0) AS AuditAvgTimer,
- COALESCE(C.AuditCount,0) AS AuditCNTCount,
- COALESCE(C.TimerCount,0) AS AuditCNTTimerCount,
- COALESCE(C.AvgTimer,0) AS AuditCNTAvgTimer,
- COALESCE(D.AuditCount,0) AS AuditWTOCount,
- COALESCE(D.TimerCount,0) AS AuditWTOTimerCount,
- COALESCE(D.AvgTimer,0) AS AuditWTOAvgTimer,
- COALESCE(E.AuditCount,0) AS AuditPassCount,
- COALESCE(E.TimerCount,0) AS AuditPassTimerCount,
- COALESCE(E.AvgTimer,0) AS AuditPassAvgTimer,
- COALESCE(F.AuditCount,0) AS AuditFailCount,
- COALESCE(F.TimerCount,0) AS AuditFailTimerCount,
- COALESCE(F.AvgTimer,0) AS AuditFailAvgTimer,
- COALESCE(G.AuditCount,0) AS QCCount,
- COALESCE(G.TimerCount,0) AS QCTimerCount,
- COALESCE(G.AvgTimer,0) AS QCAvgTimer,
- COALESCE(H.AuditCount,0) AS QCPassCount,
- COALESCE(H.TimerCount,0) AS QCPassTimerCount,
- COALESCE(H.AvgTimer,0) AS QCPassAvgTimer,
- COALESCE(I.AuditCount,0) AS QCFailCount,
- COALESCE(I.TimerCount,0) AS QCFailTimerCount,
- COALESCE(I.AvgTimer,0) AS QCFailAvgTimer,
- COALESCE(J.ReceiveCount,0) AS ReceiveCount,
- COALESCE(J.TimerCount,0) AS ReceiveTimerCount,
- COALESCE(J.AvgTimer,0) AS ReceiveAvgTimer,
- COALESCE(K.TechCount,0) AS RepairCount,
- COALESCE(K.JobEntryCount,0) AS RepairJobEntryCount,
- COALESCE(K.TimerCount,0) AS RepairTimerCount,
- COALESCE(K.AvgTimer,0) AS RepairAvgTimer,
- COALESCE(L.TechCount,0) AS RepairPassCount,
- COALESCE(L.JobEntryCount,0) AS RepairPassJobEntryCount,
- COALESCE(L.TimerCount,0) AS RepairPassTimerCount,
- COALESCE(L.AvgTimer,0) AS RepairPassAvgTimer,
- COALESCE(M.TechCount,0) AS RepairCBFCount,
- COALESCE(M.JobEntryCount,0) AS RepairCBFJobEntryCount,
- COALESCE(M.TimerCount,0) AS RepairCBFTimerCount,
- COALESCE(M.AvgTimer,0) AS RepairCBFAvgTimer,
- COALESCE(N.TechCount,0) AS RefurbishCount,
- COALESCE(N.JobEntryCount,0) AS RefurbishJobEntryCount,
- COALESCE(N.TimerCount,0) AS RefurbishTimerCount,
- COALESCE(N.AvgTimer,0) AS RefurbishAvgTimer,
- COALESCE(O.TechCount,0) AS TechCount,
- COALESCE(O.JobEntryCount,0) AS TechJobEntryCount,
- COALESCE(O.TimerCount,0) AS TechTimerCount,
- COALESCE(O.AvgTimer,0) AS TechAvgTimer
- FROM
- DateTable AS A
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.AuditID),0) AS AuditCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- WHERE COALESCE(A.QC,0) = 0
- GROUP BY AuditDate
- ) AS B
- ON A.EntryDate = B.AuditDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.AuditID),0) AS AuditCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- WHERE COALESCE(A.CNT, 0) = 1 AND COALESCE(A.QC,0) = 0
- GROUP BY AuditDate
- ) AS C
- ON A.EntryDate = C.AuditDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.AuditID),0) AS AuditCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- WHERE COALESCE(A.WTO, 0) = 1 AND COALESCE(A.QC,0) = 0
- GROUP BY AuditDate
- ) AS D
- ON A.EntryDate = D.AuditDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.AuditID),0) AS AuditCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- WHERE COALESCE(A.QC,0) = 0 AND COALESCE(A.WTO,0) = 0 AND COALESCE(A.CNT,0) = 0 AND COALESCE(A.PASS,0) = 1
- GROUP BY AuditDate
- ) AS E
- ON A.EntryDate = E.AuditDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.AuditID),0) AS AuditCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- WHERE COALESCE(A.QC,0) = 0 AND COALESCE(A.WTO,0) = 0 AND COALESCE(A.CNT,0) = 0 AND COALESCE(A.PASS,0) = 0
- GROUP BY AuditDate
- ) AS F
- ON A.EntryDate = F.AuditDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.AuditID),0) AS AuditCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- WHERE COALESCE(A.QC,0) = 1
- GROUP BY AuditDate
- ) AS G
- ON A.EntryDate = G.AuditDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.AuditID),0) AS AuditCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- WHERE COALESCE(A.QC,0) = 1 AND COALESCE(A.PASS,0) = 1
- GROUP BY AuditDate
- ) AS H
- ON A.EntryDate = H.AuditDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.AuditID),0) AS AuditCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- WHERE COALESCE(A.QC,0) = 1 AND COALESCE(A.PASS,0) = 0
- GROUP BY AuditDate
- ) AS I
- ON A.EntryDate = I.AuditDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.InventoryID),0) AS ReceiveCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,A.ReceiveDate)) AS ReceiveDate
- FROM
- InventoryTable AS A
- GROUP BY ReceiveDate
- ) AS J
- ON A.EntryDate = J.ReceiveDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.TechID),0) AS TechCount,
- COALESCE(SUM(A.JobEntryCount),0) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,B.RepairDate)) AS RepairDate
- FROM
- (
- SELECT
- A.TechID,
- COUNT(A.JobEntryID) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS Timer
- FROM
- JobEntryTable AS A
- INNER JOIN
- JobTable AS B
- ON A.JobID = B.JobID
- WHERE
- COALESCE(B.Repair,0) = 1
- GROUP BY
- A.TechID
- ) AS A
- INNER JOIN
- TechTable AS B
- ON A.TechID = B.TechID
- GROUP BY RepairDate
- ) AS K
- ON A.EntryDate = K.RepairDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.TechID),0) AS TechCount,
- COALESCE(SUM(A.JobEntryCount),0) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,B.RepairDate)) AS RepairDate
- FROM
- (
- SELECT
- A.TechID,
- COUNT(A.JobEntryID) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS Timer
- FROM
- JobEntryTable AS A
- INNER JOIN
- JobTable AS B
- ON A.JobID = B.JobID
- WHERE
- COALESCE(B.Repair,0) = 1 AND COALESCE(A.CBF,0) = 0
- GROUP BY
- A.TechID
- ) AS A
- INNER JOIN
- TechTable AS B
- ON A.TechID = B.TechID
- GROUP BY RepairDate
- ) AS L
- ON A.EntryDate = L.RepairDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.TechID),0) AS TechCount,
- COALESCE(SUM(A.JobEntryCount),0) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,B.RepairDate)) AS RepairDate
- FROM
- (
- SELECT
- A.TechID,
- COALESCE(COUNT(A.JobEntryID),0) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS Timer
- FROM
- JobEntryTable AS A
- INNER JOIN
- JobTable AS B
- ON A.JobID = B.JobID
- WHERE
- COALESCE(B.Repair,0) = 1 AND COALESCE(A.CBF,0) = 1
- GROUP BY
- A.TechID
- ) AS A
- INNER JOIN
- TechTable AS B
- ON A.TechID = B.TechID
- GROUP BY RepairDate
- ) AS M
- ON A.EntryDate = M.RepairDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.TechID),0) AS TechCount,
- COALESCE(SUM(A.JobEntryCount),0) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,B.RepairDate)) AS RepairDate
- FROM
- (
- SELECT
- A.TechID,
- COALESCE(COUNT(A.JobEntryID),0) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS Timer
- FROM
- JobEntryTable AS A
- INNER JOIN
- JobTable AS B
- ON A.JobID = B.JobID
- WHERE
- COALESCE(B.Repair,0) = 0
- GROUP BY
- A.TechID
- ) AS A
- INNER JOIN
- TechTable AS B
- ON A.TechID = B.TechID
- GROUP BY RepairDate
- ) AS N
- ON A.EntryDate = N.RepairDate
- LEFT JOIN
- (
- SELECT
- COALESCE(COUNT(A.TechID),0) AS TechCount,
- COALESCE(SUM(A.JobEntryCount),0) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS TimerCount,
- COALESCE(AVG(A.Timer),0) AS AvgTimer,
- DATEADD(dd,0,DATEDIFF(dd,0,B.RepairDate)) AS RepairDate
- FROM
- (
- SELECT
- A.TechID,
- COALESCE(COUNT(A.JobEntryID),0) AS JobEntryCount,
- COALESCE(SUM(A.Timer),0) AS Timer
- FROM
- JobEntryTable AS A
- INNER JOIN
- JobTable AS B
- ON A.JobID = B.JobID
- GROUP BY
- A.TechID
- ) AS A
- INNER JOIN
- TechTable AS B
- ON A.TechID = B.TechID
- GROUP BY RepairDate
- ) AS O
- ON A.EntryDate = O.RepairDate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement