-- Customer specific once-script WEHK#31644.
--
-- (c) 2015 Facilitor bv
-- ONCE script WEHK#37877

SET ECHO ON
SPOOL xWEHK#37877.lst
SET DEFINE OFF;

-- Van facility lev contract (nvt) = 504 naar Facility = 441
UPDATE cnt_kenmerkcontract kc
   SET cnt_kenmerk_key =
          (SELECT kn.cnt_kenmerk_key
             FROM cnt_kenmerk ko, cnt_kenmerk kn
            WHERE ko.cnt_kenmerk_key = kc.cnt_kenmerk_key
              AND kn.cnt_srtkenmerk_key = ko.cnt_srtkenmerk_key
              AND kn.cnt_srtcontract_key = 441)
 WHERE cnt_contract_key IN
             (SELECT cnt_contract_key
                FROM cnt_contract
               WHERE ins_discipline_key = 504)
   AND cnt_kenmerk_key NOT IN (SELECT cnt_kenmerk_key
                                 FROM cnt_kenmerk
                                WHERE cnt_kenmerk_verwijder IS NOT NULL);               

UPDATE cnt_contract
   SET ins_discipline_key = 441
 WHERE ins_discipline_key = 504;

-- Van Engine = 1221 naar Operations = 841
UPDATE cnt_kenmerkcontract kc
   SET cnt_kenmerk_key =
          (SELECT kn.cnt_kenmerk_key
             FROM cnt_kenmerk ko, cnt_kenmerk kn
            WHERE ko.cnt_kenmerk_key = kc.cnt_kenmerk_key
              AND kn.cnt_srtkenmerk_key = ko.cnt_srtkenmerk_key
              AND kn.cnt_srtcontract_key = 841)
 WHERE cnt_contract_key IN
             (SELECT cnt_contract_key
                FROM cnt_contract
               WHERE ins_discipline_key = 1221)
   AND cnt_kenmerk_key NOT IN (SELECT cnt_kenmerk_key
                                 FROM cnt_kenmerk
                                WHERE cnt_kenmerk_verwijder IS NOT NULL);               
               
UPDATE cnt_contract
   SET ins_discipline_key = 841
 WHERE ins_discipline_key = 1221;

-- Van RFS = 503 naar Wehkamp group = 821
UPDATE cnt_kenmerkcontract kc
   SET cnt_kenmerk_key =
          (SELECT kn.cnt_kenmerk_key
             FROM cnt_kenmerk ko, cnt_kenmerk kn
            WHERE ko.cnt_kenmerk_key = kc.cnt_kenmerk_key
              AND kn.cnt_srtkenmerk_key = ko.cnt_srtkenmerk_key
              AND kn.cnt_srtcontract_key = 821)
 WHERE cnt_contract_key IN
             (SELECT cnt_contract_key
                FROM cnt_contract
               WHERE ins_discipline_key = 503)
   AND cnt_kenmerk_key NOT IN (SELECT cnt_kenmerk_key
                                 FROM cnt_kenmerk
                                WHERE cnt_kenmerk_verwijder IS NOT NULL);               

UPDATE cnt_contract
   SET ins_discipline_key = 821
 WHERE ins_discipline_key = 503;

COMMIT;

BEGIN adm.systrackscriptId('$Id$'); END;
/

SPOOL OFF;
