CREATE OR REPLACE VIEW view_search_user AS
    SELECT
        a.id,
        a.organization_id as organizationId,
        p.id AS personId,
        p.username,
        p.name,
        p.givenName,
        CASE
            WHEN p.givenName IS NOT NULL AND p.name IS NOT NULL
                AND p.givenName <> '' AND p.name <> ''
                THEN CONCAT(p.givenName, ' ', p.name)
            WHEN p.givenName IS NOT NULL AND p.givenName <> ''
                THEN p.givenName
            WHEN p.name IS NOT NULL AND p.name <> ''
                THEN p.name
            ELSE ''
        END AS fullName
    FROM
        opentalent.Access a
            INNER JOIN
        opentalent.Person p
        ON
            a.person_id = p.id
    WHERE adminAccess IS FALSE;

