SQL: Simple Payments, Adjustments, and Appointment Type

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 number, date of service, rendering provider, appointment type, CPT, total insurance paid and total insurance adjusted, for a date of service range you specify and a payment date range you specify.

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

Caveats

  • Voids are excluded.
  • The date of service range is separate from the payment date range. Payments may have come in any time after the date of service, including time periods after the end date. To include all payments, set the payment date range from the start of the date of service range to today’s date.
  • This only includes insurance side payments and adjustments.

SQL Code: Firebird

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

select patno, dos, cptcode, staffname as rendering_provider,code1 as appt_type, total_ins_paid, total_ins_adjusted from
(
select patno, date1 as dos, trnsxno, rend_addr_id, cptcode from archive_transactions at1 where 
archive_Flag = 1 and date1 between :dos_start and :dos_end and txnopaid = 0
) a
left outer join
(select txnopaid, sum(payment) as total_ins_paid, sum(adjustment) as total_ins_adjusted from archive_transactions where archive_flag = 1 and date1 between :payment_start and :payment_end and txnopaid >0 group by txnopaid) b on a.trnsxno = b.txnopaid
left outer join staff1 on 
staff1.staffid = a.rend_addr_id
left outer join (select appt_date,code1, patno from schedule where appt_date between :dos_start and :dos_end and visit_status not in ( 'Cancelled','No Show')) s on a.patno = s.patno and s.appt_date = a.dos
where ( total_ins_paid >= 0.01 or total_ins_adjusted >= 0.01)


SQL Code: MySQL

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

select a.patno, dos, cptcode, staffname as rendering_provider,code1 as appt_type, total_ins_paid, total_ins_adjusted from
(
select patno, date1 as dos, trnsxno, rend_addr_id, cptcode from archive_transactions at1 where 
archive_Flag = 1 and date1 between :dos_start_date and :dos_end_date and txnopaid = 0
) a
left outer join
(select txnopaid, sum(payment) as total_ins_paid, sum(adjustment) as total_ins_adjusted from archive_transactions where archive_flag = 1 and date1 between :payment_start and :payment_end and 
txnopaid >0 group by txnopaid) b on a.trnsxno = b.txnopaid
left outer join staff1 on 
staff1.staffid = a.rend_addr_id
left outer join (select appt_date,code1, patno from schedule where appt_date between :dos_start_date and :dos_end_date and visit_status not in ( 'Cancelled','No Show')) s on a.patno = s.patno and s.appt_date = a.dos
where ( total_ins_paid >= 0.01 or total_ins_adjusted >= 0.01)