SQL: Ages and CPTs of Patients Seen between 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 patient chart number, first & last name, date of service, DOB, age, and billed CPT code.

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

Caveats

  • Age is the age on the date of service, not necessarily the patient’s current age.
  • It does not include voided CPT codes.
  • Only daysheeted CPT codes appear.  
  • CPT codes must be attached to a claim.  CPTs that are still in a superbill status will not appear.
  • You must be using OP for billing.

SQL Code: Firebird

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

select patno, date1, birthdat,
floor(datediff(month, dateadd(day,-extract(day from birthdat)+1,birthdat), dateadd(day,-extract (day from birthdat)+1,date1))/12) as age_on_dos, cptcode
 from  register 
inner join archive_transactions on archive_transactions.patno  = register.patno 
where date1 between :start_date and :end_date
 and archive_flag = 1 and cptcode not in ('1','2','3','4')


SQL Code: MySQL

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

select register.patno, date1, birthdat,
floor(timestampdiff(year,birthdat,date1)) as age_on_dos, cptcode
 from  register 
inner join archive_transactions on archive_transactions.patno  = register.patno 
where date1 between :start_date and :end_date
 and archive_flag = 1 and cptcode not in ('1','2','3','4')