SELECT 
CONCAT('INSERT INTO PARTY_CONTACT (KEY_ROOT_DOMAIN_OBJECT, OJB_CONCRETE_CLASS, VISIBLE, DEFAULT_CONTACT, TYPE, KEY_PARTY, ADDRESS, AREA_CODE, AREA_OF_AREA_CODE, AREA, PARISH_OF_RESIDENCE, DISTRICT_SUBDIVISION_OF_RESIDENCE, DISTRICT_OF_RESIDENCE) VALUES (1, "net.sourceforge.fenixedu.domain.contacts.PhysicalAddress", 1, 1, "PERSONAL", ', PARTY.ID_INTERNAL, ', "', REPLACE(COALESCE(PARTY.ADDRESS, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.AREA_CODE, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.AREA_OF_AREA_CODE, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.AREA, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.PARISH_OF_RESIDENCE, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.DISTRICT_SUBDIVISION_OF_RESIDENCE, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.DISTRICT_OF_RESIDENCE, ''), '"', '\''), '");') AS ''
FROM PARTY WHERE PARTY.KEY_COUNTRY_OF_RESIDENCE IS NULL;

SELECT 
CONCAT('INSERT INTO PARTY_CONTACT (KEY_ROOT_DOMAIN_OBJECT, OJB_CONCRETE_CLASS, VISIBLE, DEFAULT_CONTACT, TYPE, KEY_PARTY, ADDRESS, AREA_CODE, AREA_OF_AREA_CODE, AREA, PARISH_OF_RESIDENCE, DISTRICT_SUBDIVISION_OF_RESIDENCE, DISTRICT_OF_RESIDENCE, KEY_COUNTRY_OF_RESIDENCE) VALUES (1, "net.sourceforge.fenixedu.domain.contacts.PhysicalAddress", 1, 1, "PERSONAL", ', PARTY.ID_INTERNAL, ', "', REPLACE(COALESCE(PARTY.ADDRESS, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.AREA_CODE, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.AREA_OF_AREA_CODE, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.AREA, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.PARISH_OF_RESIDENCE, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.DISTRICT_SUBDIVISION_OF_RESIDENCE, ''), '"', '\''), '", "', REPLACE(COALESCE(PARTY.DISTRICT_OF_RESIDENCE, ''), '"', '\''), '", ', PARTY.KEY_COUNTRY_OF_RESIDENCE, ');') AS ''
FROM PARTY WHERE PARTY.KEY_COUNTRY_OF_RESIDENCE IS NOT NULL;
