SQL: All Surveys for Dates

There are two versions of this SQL: Firebird and MySQL. The MySQL version only applies to clients who are have migrated to MySQL.. All other Practices should continue to use the Firebird version of this code. Click to expand and copy the code you need. If you are unsure which code to use, please check with your Practice Administrator.

About

This report shows all surveys and status and results by date.

A sample image of this SQL report run in the Database Viewer is shown below:

Caveats

None.

SQL Code: Firebird

To highlight and copy the code below to your clipboard, simply click the Copy button.

select patno, fname, lname, birthdat, cast(quest_result_header.admin_date as date) as qdate1, quest_questionnaire_header.title as title1,
 quest_result_header.score as score1, quest_result_header.result_alpha, result_abnormal, c.descript as stage
from register
left outer join quest_result_header on quest_result_header.patno = register.patno
inner join quest_questionnaire_header on quest_questionnaire_header.questionhead_id =  quest_result_header.questionhead_id
inner join (select * from code_table where group_id = 3) c on c.ref_id = quest_result_header.stage
where admin_date  between :start_date and :end_date
order by patno, qdate1 desc


SQL Code: MySQL

To highlight and copy the code below to your clipboard, simply click the Copy button.

select register.patno, fname, lname, birthdat, cast(quest_result_header.admin_date as date) as qdate1, quest_questionnaire_header.title as title1,
 quest_result_header.score as score1, quest_result_header.result_alpha, result_abnormal, c.descript as stage
from register
left outer join quest_result_header on quest_result_header.patno = register.patno
inner join quest_questionnaire_header on quest_questionnaire_header.questionhead_id =  quest_result_header.questionhead_id
inner join (select * from code_table where group_id = 3) c on c.ref_id = quest_result_header.stage
where admin_date  between :start_date and :end_date
order by patno, qdate1 desc