-- Customer specific once-script BLCC#35031/AfnemenDefault.
--
-- (c) 2016  Facilitor B.V.
--
-- Support: +31 53 4800700
SET ECHO ON
SPOOL xBLCC35031.lst
SET DEFINE OFF

-- Afnemen _Default (PROD-key=1)
DELETE FROM fac_gebruikersgroep gg
      WHERE gg.fac_groep_key = 1
            AND EXISTS
                  (SELECT 1
                     FROM prs_perslid p, prs_v_afdeling_boom ab
                    WHERE     p.prs_afdeling_key = ab.prs_afdeling_key
                          AND ab.prs_bedrijf_key IN (2441, 2442)
                          AND p.prs_perslid_key = gg.prs_perslid_key);

-- Toewijzen SSC FE (PROD-key=321)
INSERT INTO fac_gebruikersgroep (fac_groep_key, prs_perslid_key)
   SELECT 321, p.prs_perslid_key
     FROM prs_v_aanwezigperslid p, prs_v_afdeling_boom ab
    WHERE p.prs_afdeling_key = ab.prs_afdeling_key
          AND ab.prs_bedrijf_key IN (2441, 2442)
          AND NOT EXISTS
                (SELECT 1
                   FROM fac_gebruikersgroep
                  WHERE fac_groep_key = 321
                        AND prs_perslid_key = p.prs_perslid_key);

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