--
-- $Id$
--
-- Script containing customer specific sql statements for the AAXX database

DEFINE thisfile = 'AAXX#40683-2.SQL'
DEFINE dbuser   = '^AA|^ASMS|^GULU|^NMMS|^RABO|^ZKHM'

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 fac_gebruikersgroep (fac_groep_key, 
                                 prs_perslid_key
                                )                   
      SELECT f.fac_groep_key,
             p.prs_perslid_key
        FROM prs_perslid p,
             fac_groep f
       WHERE p.prs_perslid_naam = 'Afmelder1'
       AND p.prs_perslid_verwijder IS NULL
       AND f.fac_groep_upper = '_DEFAULT'
       AND NOT EXISTS (SELECT * FROM fac_gebruikersgroep WHERE fac_groep_key = (SELECT fac_groep_key
                                                                                FROM fac_groep
                                                                                WHERE fac_groep_upper = '_DEFAULT') 
                                                                                AND prs_perslid_key = 
                                                                                    (SELECT prs_perslid_key 
                                                                                    FROM prs_perslid 
                                                                                    WHERE prs_perslid_naam = 'Afmelder1' 
                                                                                    AND prs_perslid_verwijder IS NULL));
                                                                                                      
INSERT INTO fac_gebruikersgroep (fac_groep_key, 
                                 prs_perslid_key 
                                )                   
      SELECT f.fac_groep_key,
             p.prs_perslid_key
        FROM prs_perslid p,
             fac_groep f
       WHERE p.prs_perslid_naam = 'Afmelder1'
       AND p.prs_perslid_verwijder IS NULL
       AND f.fac_groep_upper = 'LEV LEVERANCIER'
       AND NOT EXISTS (SELECT * FROM fac_gebruikersgroep WHERE fac_groep_key = (SELECT fac_groep_key
                                                                                FROM fac_groep
                                                                                WHERE fac_groep_upper = 'LEV LEVERANCIER') 
                                                                                AND prs_perslid_key = 
                                                                                    (SELECT prs_perslid_key 
                                                                                    FROM prs_perslid 
                                                                                    WHERE prs_perslid_naam = 'Afmelder1' 
                                                                                    AND prs_perslid_verwijder IS NULL));

------ payload end   ------

SET DEFINE OFF
BEGIN adm.systrackscriptId ('$Id$', 0); END;
/

COMMIT;
SET ECHO OFF
SPOOL OFF
SET DEFINE ON
PROMPT Logfile of this upgrade is: &fcltlogfile