--
-- $Id$
--
-- kenmerk kostenplaatsen met eigen tabel vervangen door nieuw kenmerk obv prs_kostenplaats tabel

DEFINE thisfile = 'STAM#49507.SQL'
DEFINE dbuser   = '^STAM'

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

-- eerste de omschrijving in de eigen tabel aanpassen naar de nieuwe juiste kpl codes
UPDATE fac_usrdata
   SET fac_usrdata_omschr =
          CASE fac_usrdata_code
             WHEN 'I1761T' THEN 'I176.P.1T.J'
             WHEN 'I1102A' THEN 'I110.P.2A.J'
             WHEN 'I1933P' THEN 'I193.P.3P.J'
             WHEN 'H329NE' THEN 'H329.N.NE.J'
             WHEN 'I1933A' THEN 'I193.P.3A.J'
             WHEN 'H015MB' THEN 'H015.M.MB.J'
             WHEN 'H016MI' THEN 'H016.M.MI.J'
             WHEN 'H137MB' THEN 'H137.M.MB.J'
             WHEN 'H408IF' THEN 'H408.I.IF.J'
             WHEN 'I2041G' THEN 'I204.P.1G.J'
             WHEN 'H329NF' THEN 'H329.N.NF.J'
             WHEN 'I1922D' THEN 'I192.P.2D.J'
             WHEN 'I2035A' THEN 'I203.P.5A.J'
             WHEN 'I203IK' THEN 'I203.I.IK.J'
             WHEN 'I2014B' THEN 'I203.P.4B.J'
             WHEN 'H479IA' THEN 'H479.I.IA.J'
             WHEN 'I180IA' THEN 'I180.I.IA.J'
             WHEN 'I1934C' THEN 'I193.P.4C.J'
             WHEN 'H472LA' THEN 'H472.L.LA.J'
             WHEN 'I1933C' THEN 'I193.P.3C.J'
             WHEN 'H137OF' THEN 'H137.O.OF.J'
             ELSE fac_usrdata_code
          END
 WHERE fac_usrtab_key = 224;

-- dan het nieuwe kenmerk vulllen
INSERT INTO mld_kenmerkmelding (mld_melding_key, mld_kenmerk_key, mld_kenmerkmelding_waarde)
   SELECT mld_melding_key, new_kenmerkkey, prs_kostenplaats_key
     FROM (SELECT km.mld_melding_key,
                  fac_usrdata_upper,
                  k.mld_stdmelding_key,
                  k.mld_kenmerk_key,
                  kw.fac_usrdata_omschr
             FROM mld_kenmerk k, mld_kenmerkmelding km, fac_usrdata kw
            WHERE     k.mld_kenmerk_key = km.mld_kenmerk_key
                  AND km.mld_kenmerkmelding_waarde = kw.fac_usrdata_key
                  AND k.mld_srtkenmerk_key = 301) OLD,
          (SELECT k.mld_stdmelding_key new_stdmeldingkey,
                  k.mld_kenmerk_key new_kenmerkkey
             FROM mld_kenmerk k
            WHERE k.mld_srtkenmerk_key = 701) NEW,
          prs_kostenplaats kp
    WHERE old.mld_stdmelding_key = new.new_stdmeldingkey
          AND kp.prs_kostenplaats_upper(+) = fac_usrdata_omschr; 

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