-- upgrade to show list the original respondent 
-- of the survey


create or replace view survey_responses_latest as
select sr.*, o.creation_date,
       o.creation_user,
        survey_response.initial_user_id(sr.response_id) as initial_user_id
  from survey_responses sr,
  acs_objects o,
  (select max(response_id) as response_id
          from survey_responses
         group by nvl(initial_response_id, response_id)) latest
  where nvl(sr.initial_response_id,sr.response_id) = o.object_id
  and sr.response_id= latest.response_id;

