--
-- $Id$
--
-- Ruimt foutieve tracking van opdracht-bijlage toevoegen op

DEFINE thisfile = 'FSN#38419.sql'
DEFINE dbuser   = '^' || USER
DEFINE custid   = USER

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

SELECT *
  FROM fac_tracking tr
 WHERE fac_tracking_oms LIKE '% toegevoegd: %'
       AND fac_tracking_datum BETWEEN TO_DATE ('2016-10-06', 'YYYY-MM-DD')
                                  AND  TO_DATE ('2016-11-04', 'YYYY-MM-DD')
       AND EXISTS (SELECT 1
                     FROM mld_opdr
                    WHERE mld_opdr_key = tr.fac_tracking_refkey)
       AND tr.fac_srtnotificatie_key =
             (SELECT fac_srtnotificatie_key
                FROM fac_srtnotificatie srt
               WHERE fac_srtnotificatie_code = 'MLDUPD');

DELETE
  FROM fac_tracking tr
 WHERE fac_tracking_oms LIKE '% toegevoegd: %'
       AND fac_tracking_datum BETWEEN TO_DATE ('2016-10-06', 'YYYY-MM-DD')
                                  AND  TO_DATE ('2016-11-04', 'YYYY-MM-DD')
       AND EXISTS (SELECT 1
                     FROM mld_opdr
                    WHERE mld_opdr_key = tr.fac_tracking_refkey)
       AND tr.fac_srtnotificatie_key =
             (SELECT fac_srtnotificatie_key
                FROM fac_srtnotificatie srt
               WHERE fac_srtnotificatie_code = 'MLDUPD');

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

@@ &custid