--
-- $Id$
--

DEFINE thisfile = 'ARAI#60068.SQL'
DEFINE dbuser   = '^ARAI'

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;
SET DEFINE OFF

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

UPDATE ins_srtgroep
   SET ins_discipline_key = 1921
 WHERE ins_srtgroep_key = 142;

-- direct maar even wat andere onzuiverheden opschonen...
UPDATE INS_DEEL d
   SET d.ins_discipline_key =
           (SELECT isg.ins_discipline_key
              FROM ins_deel id, ins_srtdeel isd, ins_srtgroep isg
             WHERE     id.ins_srtdeel_key = isd.ins_srtdeel_key
                   AND isd.ins_srtgroep_key = isg.ins_srtgroep_key
                   AND isg.ins_srtgroep_key <> 142
                   AND id.ins_discipline_key <> isg.ins_discipline_key
                   AND d.ins_deel_key = id.ins_deel_key)
 WHERE d.ins_deel_key IN
           (SELECT id.ins_deel_key
              FROM ins_deel id, ins_srtdeel isd, ins_srtgroep isg
             WHERE     id.ins_srtdeel_key = isd.ins_srtdeel_key
                   AND isd.ins_srtgroep_key = isg.ins_srtgroep_key
                   AND isg.ins_srtgroep_key <> 142
                   AND id.ins_discipline_key <> isg.ins_discipline_key
                   AND id.ins_deel_verwijder IS NULL
                   AND isd.ins_srtdeel_verwijder IS NULL
                   AND isg.ins_srtgroep_verwijder IS NULL
                   AND d.ins_deel_key = id.ins_deel_key);
                   
COMMIT;
 
------ 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
                                           


