Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagesql
SELECT
    p.student_number,
    p.personal_title,
    p.first_name,
    p.middle_name,
    p.last_name,
    p.suffix,
    p.single_name,
    p.nickname,
    p.printed_name,
    TRIM(COALESCE(ecd.property_name,'') || ' ' || COALESCE(ecd.street_subaddress,'')) AS postal_address1,
    TRIM(COALESCE(ecd.street_number,'') || ' ' || COALESCE(ecd.street_name,'')) AS postal_address2,
    ecd.city,
    CASE 
        WHEN ecd.state_province_geo_id IS NULL THEN ecd.state
        ELSE sg.geo_name
    END AS state,
    ecd.postal_code AS postal_state_code,
    CASE 
        WHEN ecd.country_geo_id IS NULL THEN ''
        ELSE cg.geo_name
    END AS postal_country
FROM
    person p
JOIN edu_contact_details ecd ON ecd.party_id = p.party_id AND ecd.role_type_id = 'RESIDENTIAL'
LEFT JOIN geo sg ON sg.geo_type_id = 'STATE' AND sg.geo_id = ecd.state_province_geo_id
LEFT JOIN geo cg ON cg.geo_type_id = 'COUNTRY' AND cg.geo_id = ecd.country_geo_id
WHERE TRUE

...