postgresql7.1
select count(distinct survey_response__initial_user_id(response_id))
from
survey_responses
where survey_id=:survey_id
select min(question_id) as question_id,
question_text
from survey_questions
where section_id=:section_id
group by question_text
order by min(sort_order)
select question_id, required_p
from survey_questions where
section_id=:section_id and
question_text = (select question_text from
survey_questions where question_id=:q_id)
SELECT survey_question__new (
:new_question_id,
:section_id,
:new_sort_order,
:question_text,
:abstract_data_type,
:required_p,
:active_p,
:presentation_type,
:presentation_options,
:presentation_alignment,
:question_html_p,
:summary_type,
:answer_description,
:predefined_question_id,
:user_id,
:section_id,
:new_question_id
);
select survey__new (
NULL,
:name,
:description,
:description_html_p,
:single_response_p,
:editable_p,
:enabled_p,
:single_section_p,
:type,
:display_type,
:package_id,
:public_p,
:user_id,
:package_id
);
select survey_section__new (
:new_section_id,
:new_survey_id,
:name,
:description,
:description_html_p,
:sort_key,
:branch_p,
:branched_p,
:block_section_p,
:page_break_p,
:user_id,
:package_id,
:new_section_id
);
select r.initial_response_id, o.creation_user as responding_user_id, r.response_id,
u.first_names || ' ' || u.last_name as user_name,
edit_p,
o.creation_date as response_date
from (select survey_response__initial_response_id(response_id) as initial_response_id,
response_id, (case when initial_response_id is NULL then 'f' else 't' end) as edit_p
from survey_responses) r, acs_objects o
left outer join acs_users_all u on (o.creation_user = u.user_id)
where r.response_id=:response_id
and r.response_id = o.object_id
select coalesce(max(sort_key),0) from
survey_sections s,survey_question_responses qr, survey_questions q
where
qr.response_id=:response_id and qr.question_id=q.question_id and s.section_id=q.section_id
select
sq.response_id,
sq.question_id,
sq.email,
sq.first_names,
sq.last_name,
sq.user_id,
sq.creation_date,
resp.boolean_answer,
resp.number_answer,
resp.date_answer,
resp.varchar_answer,
resp.clob_answer,
resp.attachment_answer,
resp.label
from
(select
sqr.response_id,
sqr.question_id,
sqr.boolean_answer,
sqr.number_answer,
sqr.date_answer,
sqr.varchar_answer,
sqr.clob_answer,
sqr.attachment_answer,
sqc.label,
sqc.sort_order
from
survey_responses sr
inner join
survey_question_responses sqr
on (sr.response_id = sqr.response_id)
right outer join
survey_question_choices sqc
on (sqr.question_id = sqc.question_id
and sqr.choice_id = sqc.choice_id)
where
sr.survey_id=:survey_id) resp
right outer join
(select r.response_id,
q.question_id,
u.email,
u.first_names,
u.last_name,
r.user_id,
r.creation_date,
q.abstract_data_type,
q.sort_order,
ss.sort_key
from survey_questions q, (select initial_user_id as user_id, creation_date, response_id from survey_responses_latest rt where survey_id=:survey_id) r, acs_users_all u, survey_sections ss
where ss.survey_id=:survey_id
and q.section_id=ss.section_id
and r.user_id = u.user_id) sq
on (sq.response_id = resp.response_id
and sq.question_id = resp.question_id)
order by
sq.response_id,
sq.sort_key,
sq.sort_order,
sq.question_id,
resp.sort_order
select
sq.response_id,
sq.question_id,
sq.email,
sq.first_names,
sq.last_name,
sq.user_id,
sq.creation_date,
resp.boolean_answer,
resp.number_answer,
resp.date_answer,
resp.varchar_answer,
resp.clob_answer,
resp.attachment_answer,
resp.label
from
(select
sqr.response_id,
sqr.question_id,
sqr.boolean_answer,
sqr.number_answer,
sqr.date_answer,
sqr.varchar_answer,
sqr.clob_answer,
sqr.attachment_answer,
sqc.label,
sqc.sort_order
from
survey_responses sr
inner join
survey_question_responses sqr
on (sr.response_id = sqr.response_id)
right outer join survey_question_choices sqc
on (sqr.question_id = sqc.question_id
and sqr.choice_id = sqc.choice_id)
where
sr.survey_id=:survey_id) resp left outer join
(select r.response_id,
q.question_id,
u.email,
u.first_names,
u.last_name,
r.user_id,
r.creation_date,
q.abstract_data_type,
q.sort_order,
ss.sort_key
from survey_questions q
inner join survey_sections ss on
(q.section_id=ss.section_id)
inner join
(select initial_user_id as user_id, survey_id, creation_date, response_id from survey_responses_latest rt where survey_id=:survey_id) r
on (ss.survey_id = r.survey_id)
right outer join cc_users u on
(r.user_id = u.user_id)
where ss.survey_id=:survey_id) sq
on (sq.response_id = resp.response_id
and sq.question_id = resp.question_id)
order by
sq.response_id,
sq.sort_key,
sq.sort_order,
sq.question_id,
resp.sort_order
select survey_question__new (
:question_id,
:section_id,
:sort_order,
:question_text,
:abstract_data_type,
:required_p,
:active_p,
:presentation_type,
:presentation_options,
:presentation_alignment,
:question_html_p,
:summary_type,
:answer_description,
NULL,
:creation_user,
:section_id,
:pretty_id
)