--
-- $Id$
--
-- Aanmaken contactpersonen

DEFINE thisfile = 'FCLT#56045_5.SQL'
DEFINE dbuser   = '^VOLK'

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 ------
DECLARE
    v_errorhint   VARCHAR2 (200);

    CURSOR c_contact IS
        SELECT p.prs_perslid_naam, p.prs_perslid_key, b.prs_bedrijf_key
          FROM prs_perslid p, prs_srtperslid f, prs_bedrijf b
         WHERE     p.prs_srtperslid_key = f.prs_srtperslid_key
               AND UPPER (f.prs_srtperslid_omschrijving) = 'CONTACTPERSOON'
               AND UPPER (p.prs_perslid_email) = b.prs_bedrijf_naam_upper;
               
BEGIN
    FOR rec IN c_contact
    LOOP
        INSERT INTO prs_contactpersoon (prs_bedrijf_key,
                                        prs_perslid_key,
                                        prs_contactpersoon_naam)
                 VALUES (rec.prs_bedrijf_key,
                         rec.prs_perslid_key,
                         substr(rec.prs_perslid_naam, 1, 30));
    END LOOP;

    COMMIT;
END;
/


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