--
-- $Id$
--
-- correctie relatietype bij nieuw opdrachttype

DEFINE thisfile = 'AAHB#51536.sql'
DEFINE dbuser   = '^AAHB'

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

   INSERT INTO mld_kenmerkopdr (mld_kenmerk_key, mld_opdr_key, mld_kenmerkopdr_waarde)
   SELECT k.mld_kenmerk_key, o.mld_opdr_key, b.prs_relatietype_key
     FROM mld_opdr o,
          mld_kenmerk k,
          mld_srtkenmerk sk,
          prs_bedrijf b
    WHERE k.mld_srtkenmerk_key = sk.mld_srtkenmerk_key
      AND sk.mld_srtkenmerk_omschrijving = 'Relatietype'
      AND o.mld_typeopdr_key = k.mld_typeopdr_key
      AND o.mld_uitvoerende_keys = b.prs_bedrijf_key
      AND NOT EXISTS
             (SELECT mld_kenmerkopdr_key
                FROM mld_kenmerkopdr ko
               WHERE ko.mld_opdr_key = o.mld_opdr_key AND ko.mld_kenmerk_key = k.mld_kenmerk_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
