SQL: Encounter Template Usage Count for Date Range

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 SQL displays Encounter Template use counts for a specified date range. This information is used to determine which Encounter Templates were applied to Encounters the most for the date range specified by the user.

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

SQL Code: Firebird

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

select et.enc_form_template as template_name, count(en.note_id) as use_count
from enc_attach ea
inner join enc_note et on et.note_id=ea.attach_id
inner join enc_note en on en.note_id=ea.enc_id
where ea.enc_table='ENC_NOTE'
and ea.attach_table='Template'
and ea.attach_date between :start_date and :end_date
group by et.enc_form_template
order by 2 desc


SQL Code: MySQL

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

select et.enc_form_template as template_name, count(en.note_id) as use_count
from enc_attach ea
inner join enc_note et on et.note_id=ea.attach_id
inner join enc_note en on en.note_id=ea.enc_id
where ea.enc_table='ENC_NOTE'
and ea.attach_table='Template'
and ea.attach_date between :start_date and :end_date
group by et.enc_form_template
order by 2 desc