/* Formatted on 5-9-2018 17:41:53 (QP5 v5.136.908.31019) */
--
-- $Id$--
-- Vul de aantallen in voor MJOB objecten op basis van de waarde in het kenmerk aantal

DEFINE thisfile = 'PNBR#38207_2.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_deel_aantal IS NOT NULL
                  AND d.ins_deel_aantal > 0
                  AND d.ins_discipline_key = 3201
                  AND k.ins_kenmerk_key = 1841)
 WHERE     d.ins_discipline_key = 3201
       AND ins_deel_aantal IS NOT NULL
       AND ins_deel_aantal > 0
       AND ins_deel_omschrijving LIKE '02%'
       AND ins_deel_key IN
                (SELECT d2.ins_deel_key
                   FROM ins_srtdeel sd, ins_kenmerkdeel k, ins_deel d2
                  WHERE     d2.ins_srtdeel_key = sd.ins_srtdeel_key
                        AND k.ins_deel_key = d2.ins_deel_key
                        AND k.ins_kenmerkdeel_waarde IS NOT NULL
                        AND k.ins_kenmerkdeel_waarde > 0
                        AND d2.ins_deel_aantal IS NOT NULL
                        AND d.ins_deel_aantal > 0
                        AND d2.ins_discipline_key = 3201
                        AND k.ins_kenmerk_key = 1841);


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