-- $Id$
--
-- Aanpassen oude MJOB meldingenstructuur naar 2023.2 structuur

DEFINE thisfile = 'BVB1#79789.SQL'
DEFINE dbuser   = '^BVB1'

SET ECHO ON
SET DEFINE ON
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
COLUMN fcltcusterr NEW_VALUE fcltcusterr NOPRINT;
WHENEVER SQLERROR CONTINUE;
SELECT adm.getscriptspoolfile('&thisfile') AS fcltlogfile FROM DUAL;
SPOOL &fcltlogfile
WHENEVER SQLERROR EXIT;
SELECT adm.checkscriptcust('&dbuser') AS fcltcusterr FROM DUAL;
WHENEVER SQLERROR CONTINUE;
PROMPT &fcltcusterr
SET DEFINE OFF

------ payload begin ------


DECLARE
    CURSOR c IS
        SELECT mld_melding_parentkey, mld_melding_key
          FROM mld_melding m, mld_stdmelding std, mld_discipline d
         WHERE     mld_melding_parentkey IS NOT NULL
               AND m.mld_stdmelding_key = std.mld_stdmelding_key
               AND std.mld_ins_discipline_key = d.ins_discipline_key
               AND ins_srtdiscipline_key = 21; -- planmatig onderhoud
BEGIN
    FOR rec IN c
    LOOP
        UPDATE mld_melding_object
           SET mld_melding_key = rec.mld_melding_parentkey
         WHERE mld_melding_key = rec.mld_melding_key;
    END LOOP;
END;
/


------ 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