Files
Customer/onces/PLAT/PLAT#54019.sql
Maykel Geerdink 0a2784dcd6 PLAT#54019: aiai mjob console.
svn path=/Customer/; revision=38569
2018-07-18 14:05:17 +00:00

118 lines
7.5 KiB
SQL

--
-- $Id$
--
-- Dubbele actieve ins_deelsrtcontrole records verwijderen.
DEFINE thisfile = 'PLAT#54019.sql'
DEFINE dbuser = '^WOMA'
SET ECHO ON
SET DEFINE ON
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
WHENEVER SQLERROR EXIT;
SELECT adm.scriptspoolfile('&dbuser', '&thisfile') AS fcltlogfile FROM DUAL;
WHENEVER SQLERROR CONTINUE;
SPOOL &fcltlogfile
SET DEFINE OFF
------ payload begin ------
-- Record verwijderen die de aiai veroorzaakt.
-- Er zijn twee ingeplande inspecties voor dezelfde taak. Van deze twee inspecties de inspectie met de laagste ins_deelsrtcontrole_key verwijderen.
-- ins_deel_key IN (5924)
DELETE FROM ins_deelsrtcontrole
WHERE ins_deelsrtcontrole_key IN (SELECT min_idsc
FROM ( SELECT idsc.ins_deel_key,
COUNT(idsc.ins_deelsrtcontrole_key) aantal,
MIN(idsc.ins_deelsrtcontrole_key) min_idsc,
MAX(idsc.ins_deelsrtcontrole_key) max_idsc
FROM ins_deelsrtcontrole idsc
WHERE idsc.ins_deelsrtcontrole_status IN (0)
AND idsc.ins_scenario_key = 1
GROUP BY idsc.ins_deel_key)
WHERE aantal = 2);
-- Nu de records verwijderen die door het verschuiven van het bedrag ook de foutmelding kunnen veroorzaken.
-- Verwijderen van de ingeplande inspecties als er na deze ingeplande inspectie nog een geaccordeerde inspecties is met een grotere ins_deelsrtcontrole_key key.
-- Deze situatie mag niet voorkomen.
-- 66 stuks
DELETE FROM ins_deelsrtcontrole
WHERE ins_deelsrtcontrole_key IN (SELECT min_idsckey
FROM (SELECT ins_deel_key,
aantal,
min_idsckey,
max_idsckey,
(SELECT idsc2.ins_deelsrtcontrole_status
FROM ins_deelsrtcontrole idsc2
WHERE idsc2.ins_deelsrtcontrole_key = min_idsckey) eerste_status,
(SELECT idsc2.ins_deelsrtcontrole_status
FROM ins_deelsrtcontrole idsc2
WHERE idsc2.ins_deelsrtcontrole_key = max_idsckey) laatste_status
FROM ( SELECT idsc.ins_deel_key,
COUNT(idsc.ins_deelsrtcontrole_key) aantal,
MAX(idsc.ins_deelsrtcontrole_key) max_idsckey,
MIN(idsc.ins_deelsrtcontrole_key) min_idsckey
FROM ins_deelsrtcontrole idsc
WHERE idsc.ins_deelsrtcontrole_status IN (0, 2)
AND idsc.ins_scenario_key = 1
GROUP BY idsc.ins_deel_key)
WHERE aantal > 1)
WHERE aantal = 2
AND eerste_status = 0
AND laatste_status = 2);
-- Verwijderen van de ingeplande inspecties als er na deze ingeplande inspectie nog een voltooide inspecties is met een grotere ins_deelsrtcontrole_key key.
-- Deze situatie mag niet voorkomen.
-- ins_deel_key IN (497, 501, 677, 1776, 1974, 2000 ,4032, 5943, 6361, 6381)
DELETE FROM ins_deelsrtcontrole
WHERE ins_deelsrtcontrole_key IN (SELECT (SELECT ins_deelsrtcontrole_key
FROM ins_deelsrtcontrole idsc2
WHERE idsc2.ins_deel_key = xx.ins_deel_key
AND idsc2.ins_srtcontrole_key = xx.ins_srtcontrole_key
AND idsc2.ins_scenario_key = 1
AND idsc2.ins_deelsrtcontrole_status = 0) ins_deelsrtcontrole_key0
FROM (SELECT ins_deel_key,
ins_srtcontrole_key,
aantal,
min_idsckey,
max_idsckey,
(SELECT idsc2.ins_deelsrtcontrole_status
FROM ins_deelsrtcontrole idsc2
WHERE idsc2.ins_deelsrtcontrole_key = min_idsckey) eerste_status,
(SELECT idsc2.ins_deelsrtcontrole_status
FROM ins_deelsrtcontrole idsc2
WHERE idsc2.ins_deelsrtcontrole_key = max_idsckey) laatste_status
FROM ( SELECT idsc.ins_deel_key,
ins_srtcontrole_key,
COUNT(idsc.ins_deelsrtcontrole_key) aantal,
MAX(idsc.ins_deelsrtcontrole_key) max_idsckey,
MIN(idsc.ins_deelsrtcontrole_key) min_idsckey
FROM ins_deelsrtcontrole idsc
WHERE idsc.ins_deelsrtcontrole_status IN (0, 6)
AND idsc.ins_scenario_key = 1
GROUP BY idsc.ins_deel_key,
ins_srtcontrole_key)
WHERE aantal > 1) xx
WHERE xx.aantal >= 2
AND EXISTS
(SELECT ins_deelsrtcontrole_key
FROM ins_deelsrtcontrole idsc2
WHERE idsc2.ins_deel_key = xx.ins_deel_key
AND idsc2.ins_srtcontrole_key = xx.ins_srtcontrole_key
AND idsc2.ins_scenario_key = 1
AND idsc2.ins_deelsrtcontrole_status = 0)
AND xx.laatste_status = 6);
------ payload end ------
SET DEFINE OFF
BEGIN adm.systrackscriptId ('$Id$', 1); END;
/
COMMIT;
SET ECHO OFF
SPOOL OFF
SET DEFINE ON
PROMPT Logfile of this upgrade is: &fcltlogfile