--
-- $Id$
--
-- Update de laatste dubbele afmeldtracking naar MLDUPD (= key 35)

DEFINE thisfile = 'NMMS#41468.SQL'
DEFINE dbuser   = '^NMMS'
DEFINE custid   = 'NMMS'

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 de laatste dubbele afmeldtracking naar MLDUPD (= key 35)
UPDATE fac_tracking
   SET fac_srtnotificatie_key = 35
 WHERE fac_tracking_key IN (SELECT fac_tracking_key
                              FROM (  SELECT MAX (fac_tracking_key)
                                                fac_tracking_key,
                                             mld_melding_key
                                        FROM fac_tracking t,
                                             fac_srtnotificatie st,
                                             mld_melding m
                                       WHERE t.fac_srtnotificatie_key =
                                                st.fac_srtnotificatie_key
                                             AND t.fac_tracking_refkey =
                                                   m.mld_melding_key
                                             AND st.fac_srtnotificatie_code =
                                                   'MLDAFM'
                                             AND m.mld_melding_key IN
                                                      (103780, 103781)
                                    GROUP BY mld_melding_key));
------ 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