select * from survey_predefined_questions where predefined_question_id=:predefined_question_id update survey_questions set sort_order = sort_order + 1 where section_id = :section_id and sort_order > :after select max(sort_order) from survey_questions where section_id=:section_id update survey_questions set question_text = :question_text where question_id = :question_id insert into survey_question_choices(choice_id,predef_choice_id,question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type) (select :new_choice,choice_id,:question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type from survey_predef_question_choices where question_id=:predefined_question_id) select distinct survey_question_all_choices(question_id) as all_choices from survey_questions where section_id=:section_id insert into survey_question_choices (choice_id, question_id, label, sort_order) values (:choice_id, :question_id, :trimmed_response, :count) insert into survey_choice_scores (choice_id, variable_id, score) values (:choice_id, :variable_id, :score)