UPDATE AMPPU_Fehlerdaten_CalcVals
SET
-- General
Failures_TOTAL_exklNA =
(SELECT COUNT()
FROM AQIs.dbo.Alle_Fehlerdaten
WHERE LEFT(CONVERT(NVARCHAR, [BV-05], 120), 10) = AMPPU_Fehlerdaten_CalcVals.Offline_DATE
AND RIGHT(Fehlercode,1) IN ('4','5')
AND [BV-05_Monat] = MONTH(GETDATE())
AND [BV-05_Jahr] = YEAR(GETDATE())
AND CASE WHEN Zeit_Fehler_AUS IS NULL THEN 'No'
WHEN [BV-05] >= Zeit_Fehler_AUS THEN 'Yes'
ELSE 'No' END = 'NO'),
Failures_TOTAL_inklNA =
(SELECT COUNT()
FROM AQIs.dbo.Alle_Fehlerdaten
WHERE LEFT(CONVERT(NVARCHAR, [BV-05], 120), 10) = AMPPU_Fehlerdaten_CalcVals.Offline_DATE
AND RIGHT(Fehlercode,1) IN ('4','5')
AND [BV-05_Monat] = MONTH(GETDATE())
AND [BV-05_Jahr] = YEAR(GETDATE())),
--
Orders_DailyVolume =
(SELECT COUNT(Auftrag_Nummer)
FROM Auftrags_Info
WHERE LEFT(CONVERT(NVARCHAR, Datum_Pfase_7, 120), 10) = AMPPU_Fehlerdaten_CalcVals.offline_Date
AND MONTH(Datum_Pfase_7) = MONTH(GETDATE())
AND YEAR(Datum_Pfase_7) = YEAR(GETDATE())),
sum_devices_B_monthly =
( select sum(SUpdateColSource1)
FROM (select Offline_date ,Orders_DailyVolume as SUpdateColSource1
from AMPPU_Fehlerdaten_CalcVals B
where MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date) and
YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)
group by Offline_date,Orders_DailyVolume) a ),
-- Teamleader
Failures_Teamleader_exklNA =
(SELECT SUM(Count_All)
FROM v_AMPPU_CalcValue_HOURLY
WHERE Offline_date = AMPPU_Fehlerdaten_CalcVals.Offline_DATE
AND ISNULL(Teamleader,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.Teamleader,'Null')
AND Bereich = 'Intern'
AND On_Line_Repair = 'No'
GROUP BY Teamleader),
Failures_Teamleader_inklNA =
(SELECT SUM(Count_ALL)
FROM v_AMPPU_CalcValue_HOURLY
WHERE Offline_date = AMPPU_Fehlerdaten_CalcVals.Offline_DATE
AND ISNULL(Teamleader,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.Teamleader,'Null')
AND Bereich = 'Intern'
GROUP BY Teamleader),
-- Bereich
Failures_Bereich_exklNA =
(SELECT SUM(Count_ALL)
FROM v_AMPPU_CalcValue_HOURLY
WHERE Offline_date = AMPPU_Fehlerdaten_CalcVals.Offline_DATE
AND ISNULL(Bereich,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.bereich,'Null')
AND On_Line_Repair = 'NO'
GROUP BY Bereich),
[sum_Failures_B_monthly(excl)] =
( select sum(SUpdateColSource1)
FROM (select Offline_date,Failures_Bereich_exklNA
as SUpdateColSource1 from AMPPU_Fehlerdaten_CalcVals B
where MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date) and
YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date) and
ISNULL(Bereich,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.bereich,'Null')
group by Offline_date,Failures_Bereich_exklNA ) a ),
Failures_Bereich_inklNA =
(SELECT SUM(Count_ALL)
FROM v_AMPPU_CalcValue_HOURLY
WHERE Offline_date = AMPPU_Fehlerdaten_CalcVals.Offline_DATE
AND ISNULL(Bereich,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.bereich,'Null')
GROUP BY Bereich),
sum_Failures_B_monthly =
( select sum(SUpdateColSource1)
FROM (select Offline_date,Failures_Bereich_inklNA
as SUpdateColSource1 from AMPPU_Fehlerdaten_CalcVals B
where MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date) and
YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date) and
ISNULL(Bereich,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.bereich,'Null')
group by Offline_date,Failures_Bereich_inklNA ) a ),
-- Disponent
-- Disponent
Failures_Disponent_exklNA =
(SELECT SUM(Count_ALL)
FROM v_AMPPU_CalcValue_HOURLY
WHERE Offline_date = AMPPU_Fehlerdaten_CalcVals.Offline_DATE
AND ISNULL(Disponent,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.disponent,'Null')
AND Bereich = 'Extern'
AND On_Line_Repair = 'No'
GROUP BY Disponent),
Failures_Disponent_inklNA =
(SELECT SUM(Count_ALL)
FROM v_AMPPU_CalcValue_HOURLY
WHERE Offline_date = AMPPU_Fehlerdaten_CalcVals.Offline_DATE
AND ISNULL(Disponent,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.disponent,'Null')
AND Bereich = 'Extern'
GROUP BY Disponent)
WHERE MONTH(Offline_date) = MONTH(GETDATE())
AND YEAR(Offline_date) = YEAR(GETDATE());
--
--
-- Setting the excepted DailyVolume for the current date
--
UPDATE AMPPU_Fehlerdaten_CalcVals
SET Orders_DailyVolume =
(SELECT COUNT(Auftrag_Nummer)
FROM Auftrags_Info
WHERE LEFT(CONVERT(NVARCHAR, Datum_Final_Schedule, 120), 10) = AMPPU_Fehlerdaten_CalcVals.offline_Date
group by Datum_Final_Schedule)
WHERE Offline_date = LEFT(CONVERT(NVARCHAR, GETDATE(), 120), 10);
--
-- per Day:
--
UPDATE AMPPU_Fehlerdaten_CalcVals
SET
-- General
CalcVal_TOTAL_exklNA = CASE WHEN Orders_DailyVolume = 0 THEN 0 ELSE ISNULL(Failures_TOTAL_exklNA/CONVERT(DECIMAL,Orders_DailyVolume),0) END,
CalcVal_TOTAL_inklNA = CASE WHEN Orders_DailyVolume = 0 THEN 0 ELSE ISNULL(Failures_TOTAL_inklNA/CONVERT(DECIMAL,Orders_DailyVolume),0) END,
-- Teamleader
CalcVal_Teamleader_exklNA = CASE WHEN Orders_DailyVolume = 0 THEN 0 ELSE ISNULL(Failures_Teamleader_exklNA/CONVERT(DECIMAL,Orders_DailyVolume),0) END,
CalcVal_Teamleader_inklNA = CASE WHEN Orders_DailyVolume = 0 THEN 0 ELSE ISNULL(Failures_Teamleader_inklNA/CONVERT(DECIMAL,Orders_DailyVolume),0) END,
-- Bereich
CalcVal_Bereich_exklNA = CASE WHEN Orders_DailyVolume = 0 THEN 0 ELSE ISNULL(Failures_Bereich_exklNA/CONVERT(DECIMAL,Orders_DailyVolume),0) END,
CalcVal_Bereich_inklNA = CASE WHEN Orders_DailyVolume = 0 THEN 0 ELSE ISNULL(Failures_Bereich_inklNA/CONVERT(DECIMAL,Orders_DailyVolume),0) END,
-- Disponent
CalcVal_Disponent_exklNA = CASE WHEN Orders_DailyVolume = 0 THEN 0 ELSE ISNULL(Failures_Disponent_exklNA/CONVERT(DECIMAL,Orders_DailyVolume),0) END,
CalcVal_Disponent_inklNA = CASE WHEN Orders_DailyVolume = 0 THEN 0 ELSE ISNULL(Failures_Disponent_inklNA/CONVERT(DECIMAL,Orders_DailyVolume),0) END
WHERE MONTH(Offline_date) = MONTH(GETDATE())
AND YEAR(Offline_date) = YEAR(GETDATE());
--
-- per Month:
--
UPDATE AMPPU_Fehlerdaten_CalcVals
SET
-- Bereich
-- CalcVal_B_MONAT_exklNA =
-- CASE WHEN sum_devices_B_monthly = 0 THEN 0 ELSE ( [sum_Failures_B_monthly(excl)] /sum_devices_B_monthly) END,
-- (SELECT AVG(avg_bereich)
-- FROM (SELECT Offline_date, AVG(CalcVal_Bereich_exklNA) AS avg_bereich
-- FROM AMPPU_Fehlerdaten_CalcVals b
-- WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
-- AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)
-- AND ISNULL(Bereich,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.bereich,'Null')
-- GROUP BY Offline_date, YEAR(Offline_date), MONTH(Offline_date)) a),
--CalcVal_B_MONAT_inklNA =
-- CASE WHEN sum_devices_B_monthly = 0 THEN 0 ELSE (sum_Failures_B_monthly/sum_devices_B_monthly) END,
--(SELECT AVG(avg_bereich)
--FROM (SELECT Offline_date, AVG(CalcVal_Bereich_inklNA) AS avg_bereich
-- FROM AMPPU_Fehlerdaten_CalcVals b
-- WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
-- AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)
-- AND ISNULL(Bereich,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.bereich,'Null')
-- GROUP BY Offline_date, YEAR(Offline_date), MONTH(Offline_date)) a),
-- Teamleader
CalcVal_T_MONAT_exklNA =
(SELECT AVG(avg_Teamleader)
FROM (SELECT Offline_date, AVG(CalcVal_Teamleader_exklNA) AS avg_Teamleader
FROM AMPPU_Fehlerdaten_CalcVals b
WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND ISNULL(Teamleader,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.Teamleader,'Null')
GROUP BY Offline_date, YEAR(Offline_date), MONTH(Offline_date)) a),
CalcVal_T_MONAT_inklNA =
(SELECT AVG(avg_Teamleader)
FROM (SELECT Offline_date, AVG(CalcVal_Teamleader_inklNA) AS avg_Teamleader
FROM AMPPU_Fehlerdaten_CalcVals b
WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND ISNULL(Teamleader,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.Teamleader,'Null')
GROUP BY Offline_date, YEAR(Offline_date), MONTH(Offline_date)) a),
-- Disponent
CalcVal_D_MONAT_exklNA =
(SELECT AVG(avg_Disponent)
FROM (SELECT Offline_date, AVG(CalcVal_Disponent_exklNA) AS avg_Disponent
FROM AMPPU_Fehlerdaten_CalcVals b
WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND ISNULL(Disponent,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.Disponent,'Null')
GROUP BY Offline_date, YEAR(Offline_date), MONTH(Offline_date)) a),
CalcVal_D_MONAT_inklNA =
(SELECT AVG(avg_Disponent)
FROM (SELECT Offline_date, AVG(CalcVal_Disponent_inklNA) AS avg_Disponent
FROM AMPPU_Fehlerdaten_CalcVals b
WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND ISNULL(Disponent,'Null') = ISNULL(AMPPU_Fehlerdaten_CalcVals.Disponent,'Null')
GROUP BY Offline_date, YEAR(Offline_date), MONTH(Offline_date)) a)
WHERE MONTH(Offline_date) = MONTH(GETDATE())
AND YEAR(Offline_date) = YEAR(GETDATE());
--
-- Total, per Month:
--
UPDATE AMPPU_Fehlerdaten_CalcVals
SET
--Bereich:
--CalcVal_B_TOTAL_MONAT_exklNA =
-- (SELECT ISNULL(SUM(CalcVal_B_MONAT_exklNA),0)
-- FROM (SELECT DISTINCT CalcVal_B_MONAT_exklNA
-- FROM AMPPU_Fehlerdaten_CalcVals b
-- WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
-- AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)) a),
--CalcVal_B_TOTAL_MONAT_inklNA =
-- (SELECT ISNULL(SUM(CalcVal_B_MONAT_inklNA),0)
-- FROM (SELECT DISTINCT CalcVal_B_MONAT_inklNA
-- FROM AMPPU_Fehlerdaten_CalcVals b
-- WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
-- AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)) a),
--Teamleader:
CalcVal_T_TOTAL_MONAT_exklNA =
(SELECT ISNULL(SUM(CalcVal_T_MONAT_exklNA),0)
FROM (SELECT DISTINCT CalcVal_T_MONAT_exklNA
FROM AMPPU_Fehlerdaten_CalcVals b
WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)) a),
CalcVal_T_TOTAL_MONAT_inklNA =
(SELECT ISNULL(SUM(CalcVal_T_MONAT_inklNA),0)
FROM (SELECT DISTINCT CalcVal_T_MONAT_inklNA
FROM AMPPU_Fehlerdaten_CalcVals b
WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)) a),
--Disponent:
CalcVal_D_TOTAL_MONAT_exklNA =
(SELECT ISNULL(SUM(CalcVal_D_MONAT_exklNA),0)
FROM (SELECT DISTINCT CalcVal_D_MONAT_exklNA
FROM AMPPU_Fehlerdaten_CalcVals b
WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)) a),
CalcVal_D_TOTAL_MONAT_inklNA =
(SELECT ISNULL(SUM(CalcVal_D_MONAT_inklNA),0)
FROM (SELECT DISTINCT CalcVal_D_MONAT_inklNA
FROM AMPPU_Fehlerdaten_CalcVals b
WHERE MONTH(Offline_date) = MONTH(AMPPU_Fehlerdaten_CalcVals.Offline_date)
AND YEAR(Offline_date) = YEAR(AMPPU_Fehlerdaten_CalcVals.Offline_date)) a)
WHERE MONTH(Offline_date) = MONTH(GETDATE())
AND YEAR(Offline_date) = YEAR(GETDATE());