-- Customer specific once-script IVET18. Aanpassing op IVET#27434.
-- Deze view is tevens aangepast in IVET.sql maar wordt vanwege 5.3.2 niet geleverd.

SET ECHO ON
SPOOL xIVET18.lst


CREATE OR REPLACE VIEW IVET_V_NOTI_MLD_TRANSPORT
(
   CODE,
   SENDER,
   RECEIVER,
   TEXT,
   KEY,
   XKEY
)
AS
   SELECT   'MLDNEW',
            NULL,
            69501,                            -- User DistributionCoordination
               'Nieuwe melding: '
            || m.mld_melding_key
            || ' '
            || std.mld_stdmelding_omschrijving
            || ' - '
            || dat.fac_usrdata_omschr,
            m.mld_melding_key,
            NULL
     FROM   mld_melding m,
            fac_tracking tr,
            fac_srtnotificatie str,
            mld_kenmerkmelding mkm,
            mld_kenmerk k,
            mld_srtkenmerk sk,
            fac_kenmerkdomein kd,
            fac_usrdata dat,
            mld_stdmelding std
    WHERE   mld_melding_status IN (0, 2, 3, 4, 7)            -- open meldingen
            AND tr.fac_srtnotificatie_key = str.fac_srtnotificatie_key
            AND ( (tr.fac_tracking_refkey = m.mld_melding_key
                   AND str.fac_srtnotificatie_xmlnode IN ('melding')))
            AND fac_srtnotificatie_code = 'MLDNEW'
            AND tr.fac_tracking_datum >
                  (SELECT   fac_notificatie_job_nextrun
                            - fac_notificatie_job_interval / 24
                     FROM   fac_notificatie_job
                    WHERE   fac_notificatie_job_view =
                               'IVET_V_NOTI_MLD_TRANSPORT')
            AND m.mld_stdmelding_key = 2821 -- R-Transportaanvraag-transportaanvraag
            AND mkm.mld_melding_key = m.mld_melding_key
            AND mkm.mld_kenmerk_key = 13641                    -- Kenmerk Land
            AND mkm.mld_kenmerkmelding_waarde IS NOT NULL
            AND mkm.mld_kenmerkmelding_verwijder IS NULL
            AND m.mld_stdmelding_key = std.mld_stdmelding_key
            AND mkm.mld_kenmerk_key = k.mld_kenmerk_key
            AND k.mld_srtkenmerk_key = sk.mld_srtkenmerk_key
            AND sk.fac_kenmerkdomein_key = kd.fac_kenmerkdomein_key
            AND dat.fac_usrtab_key = kd.fac_usrtab_key
            AND mkm.mld_kenmerkmelding_waarde = dat.fac_usrdata_key;

COMMIT;

SPOOL OFF

SET ECHO OFF