--
-- $Id$--
-- Vul de aantallen in voor MJOB objecten op basis van de waarde in het kenmerk aantal

DEFINE thisfile = 'PNBR#38207.SQL'
DEFINE dbuser   = '^PNBR'

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

UPDATE ins_deel d
   SET d.ins_deel_aantal =
          (SELECT fac.safe_to_number (k.ins_kenmerkdeel_waarde )
             FROM ins_srtdeel sd, ins_kenmerkdeel k
            WHERE     d.ins_srtdeel_key = sd.ins_srtdeel_key
                  AND k.ins_deel_key = d.ins_deel_key
                  AND k.ins_kenmerkdeel_waarde is not null
                  AND k.ins_kenmerkdeel_waarde > 0
                  AND d.ins_discipline_key = 3201
                  AND k.ins_kenmerk_key = 1841)
                  WHERE d.ins_discipline_key = 3201;

UPDATE ins_srtcontrole
   SET ctr_discipline_key = 3221
 WHERE ins_srtinstallatie_key IN
             (SELECT c.ins_srtinstallatie_key
                FROM ins_srtdeel sd, ins_deel d, ins_srtcontrole c
               WHERE     d.ins_srtdeel_key = sd.ins_srtdeel_key
                     AND d.ins_srtdeel_key = c.ins_srtinstallatie_key
                     AND d.ins_discipline_key = 3201);                  
                  
------ 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