Siempre recomiendo dejar de usar PIVOT
y en su lugar usar agregados condicionales. Esto da una flexibilidad mayor y, aunque requiera más texto, generarlo es solo cuestión de copiar, pegar y modificar cosas básicas.
Ejemplo:
SELECT workDayId,
COUNT( CASE WHEN clave = 'MX-SI14-06 ' THEN calif END) AS [MX-SI14-06],
COUNT( CASE WHEN clave = 'MX-SI14-14 ' THEN calif END) AS [MX-SI14-14],
COUNT( CASE WHEN clave = 'MX-AG16-529' THEN calif END) AS [MX-AG16-529],
COUNT( CASE WHEN clave = 'MX-PB10-008' THEN calif END) AS [MX-PB10-008],
COUNT( CASE WHEN clave = 'MX-AG14-546' THEN calif END) AS [MX-AG14-546],
COUNT( CASE WHEN clave = 'MX-WH10-001' THEN calif END) AS [MX-WH10-001],
COUNT( CASE WHEN clave = 'MX-AG14-079' THEN calif END) AS [MX-AG14-079],
COUNT( CASE WHEN clave = 'MX-SI14-08 ' THEN calif END) AS [MX-SI14-08],
COUNT( CASE WHEN clave = 'MX-PS14-007' THEN calif END) AS [MX-PS14-007],
COUNT( CASE WHEN clave = 'MX-PS10-068' THEN calif END) AS [MX-PS10-068],
COUNT( CASE WHEN clave = 'MX-PB14-04 ' THEN calif END) AS [MX-PB14-04],
COUNT( CASE WHEN clave = 'MX-SI14-17 ' THEN calif END) AS [MX-SI14-17],
COUNT( CASE WHEN clave = 'MX-PS10-154' THEN calif END) AS [MX-PS10-154],
COUNT( CASE WHEN clave = 'MX-AG14-597' THEN calif END) AS [MX-AG14-597],
COUNT( CASE WHEN clave = 'MX-SI10-014' THEN calif END) AS [MX-SI10-014]`
COUNT( clave) AS Total,
CASE WHEN COUNT( clave) = 15 THEN 'Completo' ELSE 'Pendiente' END AS Estatus
FROM cteMechanicals_Two
GROUP BY workDayId;
Claro está, que para hacer lo que pides, solo tendrías que hacer la suma. Como vas a usar esa suma 2 veces, se puede factorizar en un APPLY
.
SELECT workDayId,
[MX-SI14-06], [MX-SI14-14], [MX-AG16-529], [MX-PB10-008], [MX-AG14-546],
[MX-WH10-001], [MX-AG14-079], [MX-SI14-08], [MX-PS14-007], [MX-PS10-068],
[MX-PB14-04], [MX-SI14-17], [MX-PS10-154], [MX-AG14-597], [MX-SI10-014],
t.total,
CASE WHEN total = 15 THEN 'Completo' ELSE 'Pendiente' END AS Estatus
FROM (SELECT workDayId,calif,clave FROM cteMechanicals_Two) P
PIVOT (COUNT (calif)
FOR clave IN ([MX-SI14-06], [MX-SI14-14], [MX-AG16-529], [MX-PB10-008], [MX-AG14-546],
[MX-WH10-001], [MX-AG14-079], [MX-SI14-08], [MX-PS14-007], [MX-PS10-068],
[MX-PB14-04], [MX-SI14-17], [MX-PS10-154], [MX-AG14-597], [MX-SI10-014] )) AS pvt
CROSS APPLY( SELECT [MX-SI14-06] + [MX-SI14-14] + [MX-AG16-529] + [MX-PB10-008] + [MX-AG14-546] +
[MX-WH10-001] + [MX-AG14-079] + [MX-SI14-08] + [MX-PS14-007] + [MX-PS10-068] +
[MX-PB14-04] + [MX-SI14-17] + [MX-PS10-154] + [MX-AG14-597] + [MX-SI10-014] AS total) t;