-- Script containing customer specific change AAZC#30095
-- (c) 2014 FACILITOR
-- $Revision$
-- $Id$
--
-- Support: +31 53 4800710

SET ECHO ON
SET DEFINE ON
column fcltlogfile new_value fcltlogfile NOPRINT;
select UPPER(USER) || '_AAZC#30095' || '.lst' as fcltlogfile from dual;
spool &fcltlogfile
SET DEFINE OFF


-- versie null bestaat terwijl er nieuwere versies van het contract zijn
-- dan moeten we de null vervangen door 0
UPDATE cnt_contract c
   SET cnt_contract_versie = '0'
 WHERE cnt_contract_versie IS NULL
   AND EXISTS
          (SELECT cnt_contract_key
             FROM cnt_contract c2
            WHERE c.cnt_contract_nummer = c2.cnt_contract_nummer
              AND c2.cnt_contract_versie IS NOT NULL
              AND c2.cnt_contract_versie <> '0');

-- versie .0 bestaat en er bestaan geen nieuwere versies
-- dan moeten we de versie 0 vervangen door null
UPDATE cnt_contract c
   SET cnt_contract_versie = NULL
 WHERE cnt_contract_versie = '0'
   AND NOT EXISTS
          (SELECT cnt_contract_key
             FROM cnt_contract c2
            WHERE c.cnt_contract_nummer = c2.cnt_contract_nummer
              AND c2.cnt_contract_versie IS NOT NULL
              AND c2.cnt_contract_versie <> '0');

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

COMMIT;
SPOOL OFF