-- CONN#399 sql scripts
-- conn_446 is de TEST omgeving, conn_447 de PRODuctie

spool conn339b.lst;

 -- Is aangemaakt na 18-10
delete from conn.alg_gebouw where alg_gebouw_key = 19879;

delete from conn.alg_ruimte where alg_ruimte_nr = 'Onb'
and alg_ruimte_aanmaak > TO_DATE('18-10-2004', 'DD-MM-YYYY');

delete from conn.alg_verdieping where alg_verdieping_omschrijving = 'Onbekend'
and alg_verdieping_aanmaak > TO_DATE('18-10-2004', 'DD-MM-YYYY');

delete from conn.alg_gebouw where alg_gebouw_code = 'Onb'
and alg_gebouw_aanmaak > TO_DATE('18-10-2004', 'DD-MM-YYYY');


/* Formatted on 2005/01/05 10:49 (Formatter Plus v4.8.5) */
UPDATE conn.alg_gebouw g7
   SET (alg_gebouw_getekend, alg_gebouw_bruto_vloeropp, alg_gebouw_omtrek) =
          (SELECT alg_gebouw_getekend, alg_gebouw_bruto_vloeropp,
                  alg_gebouw_omtrek
             FROM conn_446.alg_gebouw g6
            WHERE g6.alg_gebouw_getekend IS NOT NULL
			AND g7.alg_gebouw_key=g6.alg_gebouw_key
			AND g7.alg_locatie_key=g6.alg_locatie_key
			AND g7.alg_gebouw_upper=g6.alg_gebouw_upper);


-- JGL: Kan dit voorkomen??
UPDATE conn.alg_gebouw g7
   SET alg_gebouw_key =
   (SELECT alg_gebouw_key
     FROM conn_446.alg_gebouw g6
    WHERE g6.alg_gebouw_verwijder is null
	 and g6.alg_locatie_key =g7.alg_locatie_key
	 and g6.alg_gebouw_upper=g7.alg_gebouw_upper);


/* Formatted on 2005/01/05 10:48 (Formatter Plus v4.8.5) */
INSERT INTO conn.alg_gebouw g7
   SELECT *
     FROM conn_446.alg_gebouw g6
    WHERE g6.alg_gebouw_key NOT IN (SELECT gg7.alg_gebouw_key
                                      FROM conn.alg_gebouw gg7)
     AND g6.alg_gebouw_verwijder is null
	 AND g6.alg_gebouw_aanmaak > TO_DATE('18-10-2004', 'DD-MM-YYYY');

/* Formatted on 2005/01/05 10:48 (Formatter Plus v4.8.5) */
INSERT INTO conn.alg_verdieping v7
   SELECT *
     FROM conn_446.alg_verdieping v6
    WHERE v6.alg_verdieping_key NOT IN (SELECT gg7.alg_verdieping_key
                                      FROM conn.alg_verdieping gg7);

/* Formatted on 2005/01/05 10:49 (Formatter Plus v4.8.5) */
UPDATE conn.alg_ruimte r7
   SET (alg_ruimte_getekend, alg_ruimte_bruto_vloeropp, alg_ruimte_omtrek) =
          (SELECT alg_ruimte_getekend, alg_ruimte_bruto_vloeropp,
                  alg_ruimte_omtrek
             FROM conn_446.alg_ruimte r6
            WHERE r6.alg_ruimte_getekend IS NOT NULL
			AND r6.alg_ruimte_key=r7.alg_ruimte_key);

/* Formatted on 2005/01/18 13:20 (Formatter Plus v4.8.5) */
UPDATE conn.alg_ruimte v7
   SET (alg_ruimte_verwijder) =
          (SELECT alg_ruimte_verwijder
             FROM conn_446.alg_ruimte r6
            WHERE r6.alg_ruimte_verwijder IS NOT NULL
              AND r6.alg_ruimte_key = v7.alg_ruimte_key)
 WHERE alg_ruimte_verwijder IS NULL;

/* Formatted on 2005/01/18 13:57 (Formatter Plus v4.8.5) */
UPDATE conn_446.alg_ruimte v6
   SET alg_srtruimte_key = NULL
 WHERE v6.alg_ruimte_key NOT IN (SELECT gg7.alg_ruimte_key
                                   FROM conn.alg_ruimte gg7)
   AND v6.alg_srtruimte_key NOT IN (SELECT alg_srtruimte_key
                                      FROM conn.alg_srtruimte);


INSERT INTO conn.alg_ruimte v7
   SELECT *
     FROM conn_446.alg_ruimte v6
    WHERE v6.alg_ruimte_key NOT IN (SELECT gg7.alg_ruimte_key
                                      FROM conn.alg_ruimte gg7);

DELETE FROM conn.CAD_TEKENING;

INSERT INTO conn.CAD_TEKENING
    SELECT *
      FROM conn_446.CAD_TEKENING;

INSERT INTO conn.ALG_TERREINSECTOR
    SELECT *
      FROM conn_446.ALG_TERREINSECTOR
     WHERE ALG_TERREINSECTOR_aanmaak >= TO_DATE('22-12-2004', 'DD-MM-YYYY');

/* Formatted on 2005/02/02 10:51 (Formatter Plus v4.8.5) */
-- Bij een aantal tekeningen is de plan en contour omgewisseld. Zet dat terug
UPDATE conn.cad_tekening
   SET cad_tekening_type = 'D'
 WHERE alg_verdieping_key IN (11372, 12241, 13848, 13068)
   AND cad_tekening_type = 'C';

UPDATE conn.cad_tekening
   SET cad_tekening_type = 'C'
 WHERE alg_verdieping_key IN (11372, 12241, 13848, 13068)
   AND cad_tekening_type = 'P';

UPDATE conn.cad_tekening
   SET cad_tekening_type = 'P'
 WHERE alg_verdieping_key IN (11372, 12241, 13848, 13068)
   AND cad_tekening_type = 'D';

COMMIT;

spool off;

-- UPDATEROUTINE voor SEQUENCES
-- Omdat moeilijk automatisch te achterhalen is voor welke kolommen
-- een sequence gebruikt wordt, is dit een handmatig werkje...
-- 9/3/98 3:58PM
-- SOURCEFILE, REQUIRES PRECOMPILES USING z:\public\msc6\bin\cl /EP UPD_SEQ.H >upd_seq.sql
--
set lines 200
set pages 0
spool upd_seq
SELECT * FROM USER_SEQUENCES;
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(alg_district_key) INTO maxval FROM alg_district; SELECT ALG_S_ALG_DISTRICT_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT ALG_S_ALG_DISTRICT_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(alg_locatie_key) INTO maxval FROM alg_locatie; SELECT ALG_S_ALG_LOCATIE_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT ALG_S_ALG_LOCATIE_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxvalt NUMBER(10); maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(alg_terreinsector_key) INTO maxval FROM alg_terreinsector; SELECT MAX(alg_gebouw_key) INTO maxvalt FROM alg_gebouw; IF maxvalt > maxval THEN maxval := maxvalt; END IF; SELECT MAX(alg_verdieping_key) INTO maxvalt FROM alg_verdieping; IF maxvalt > maxval THEN maxval := maxvalt; END IF; SELECT MAX(alg_ruimte_key) INTO maxvalt FROM alg_ruimte; IF maxvalt > maxval THEN maxval := maxvalt; END IF; SELECT ALG_S_ALG_ONROERENDGOED_KEYS.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT ALG_S_ALG_ONROERENDGOED_KEYS.nextval INTO seqval FROM DUAL; END LOOP; END;  
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(alg_regio_key) INTO maxval FROM alg_regio; SELECT ALG_S_ALG_REGIO_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT ALG_S_ALG_REGIO_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(alg_srtgebouw_key) INTO maxval FROM alg_srtgebouw; SELECT ALG_S_ALG_SRTGEBOUW_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT ALG_S_ALG_SRTGEBOUW_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(alg_srtruimte_key) INTO maxval FROM alg_srtruimte; SELECT ALG_S_ALG_SRTRUIMTE_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT ALG_S_ALG_SRTRUIMTE_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(cad_tekening_key) INTO maxval FROM cad_tekening; SELECT CAD_S_CAD_TEKENING_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT CAD_S_CAD_TEKENING_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(fac_functie_key) INTO maxval FROM fac_functie; SELECT FAC_S_FAC_FUNCTIE_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT FAC_S_FAC_FUNCTIE_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(fac_gebruiker_key) INTO maxval FROM fac_gebruiker; SELECT FAC_S_FAC_GEBRUIKER_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT FAC_S_FAC_GEBRUIKER_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(fac_rol_key) INTO maxval FROM fac_rol; SELECT FAC_S_FAC_ROL_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT FAC_S_FAC_ROL_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_deelkoppeling_key) INTO maxval FROM ins_deelkoppeling; SELECT INS_S_INS_DEELKOPPELING_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_DEELKOPPELING_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_discipline_key) INTO maxval FROM ins_discipline; SELECT INS_S_INS_DISCIPLINE_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_DISCIPLINE_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_deel_key) INTO maxval FROM ins_deel; SELECT INS_S_INS_INST_KEYS.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_INST_KEYS.nextval INTO seqval FROM DUAL; END LOOP; END; -- deel+onderdeel+element (eigenlijk)
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_kenmerkdeel_key) INTO maxval FROM ins_kenmerkdeel; SELECT INS_S_INS_KENMERKDEEL_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_KENMERKDEEL_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_kenmerk_key) INTO maxval FROM ins_kenmerk; SELECT INS_S_INS_KENMERK_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_KENMERK_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_refsrtkenmerk_key) INTO maxval FROM ins_refsrtkenmerk; SELECT INS_S_INS_REFSRTKENMERK_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_REFSRTKENMERK_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_srtgroep_key) INTO maxval FROM ins_srtgroep; SELECT INS_S_INS_SRTGROEP_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_SRTGROEP_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_srtdeel_key) INTO maxval FROM ins_srtdeel; SELECT INS_S_INS_SRTINST_KEYS.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_SRTINST_KEYS.nextval INTO seqval FROM DUAL; END LOOP; END;  -- srtdeel+srtonderdeel+srtelement (eigenlijk)
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(ins_srtkenmerk_key) INTO maxval FROM ins_srtkenmerk; SELECT INS_S_INS_SRTKENMERK_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT INS_S_INS_SRTKENMERK_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(mld_adres_key) INTO maxval FROM mld_adres; SELECT MLD_S_MLD_ADRES_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT MLD_S_MLD_ADRES_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(mld_meldbron_key) INTO maxval FROM mld_meldbron; SELECT MLD_S_MLD_MELDBRON_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT MLD_S_MLD_MELDBRON_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(mld_melding_key) INTO maxval FROM mld_melding; SELECT MLD_S_MLD_MELDING_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT MLD_S_MLD_MELDING_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(mld_oorzaak_key) INTO maxval FROM mld_oorzaak; SELECT MLD_S_MLD_OORZAAK_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT MLD_S_MLD_OORZAAK_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(mld_opdr_key) INTO maxval FROM mld_opdr; SELECT MLD_S_MLD_OPDR_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT MLD_S_MLD_OPDR_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(mld_standaardopdr_key) INTO maxval FROM mld_standaardopdr; SELECT MLD_S_MLD_STANDAARDOPDR_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT MLD_S_MLD_STANDAARDOPDR_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(mld_stdmelding_key) INTO maxval FROM mld_stdmelding; SELECT MLD_S_MLD_STDMELDING_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT MLD_S_MLD_STDMELDING_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(mld_vrije_dagen_key) INTO maxval FROM mld_vrije_dagen; SELECT MLD_S_MLD_VRIJE_DAGEN_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT MLD_S_MLD_VRIJE_DAGEN_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(prs_afdeling_key) INTO maxval FROM prs_afdeling; SELECT PRS_S_PRS_AFDELING_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT PRS_S_PRS_AFDELING_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxvalt NUMBER(10); maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(prs_srtperslid_key) INTO maxval FROM prs_srtperslid; SELECT MAX(prs_perslid_key) INTO maxvalt FROM prs_perslid; IF maxvalt > maxval THEN maxval := maxvalt; END IF; SELECT MAX(prs_bedrijf_key) INTO maxvalt FROM prs_bedrijf; IF maxvalt > maxval THEN maxval := maxvalt; END IF; SELECT PRS_S_PRS_ALLUITVOERENDE_KEYS.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT PRS_S_PRS_ALLUITVOERENDE_KEYS.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(prs_perslidwerkplek_key) INTO maxval FROM prs_perslidwerkplek; SELECT PRS_S_PRS_PERSLIDWERKPLEK_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT PRS_S_PRS_PERSLIDWERKPLEK_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
DECLARE maxval NUMBER(10); seqval NUMBER; BEGIN SELECT MAX(prs_werkplek_key) INTO maxval FROM prs_werkplek; SELECT PRS_S_PRS_WERKPLEK_KEY.nextval INTO seqval FROM DUAL; WHILE seqval<maxval LOOP SELECT PRS_S_PRS_WERKPLEK_KEY.nextval INTO seqval FROM DUAL; END LOOP; END;
/
SELECT * FROM USER_SEQUENCES;
spool off
