SQL: One Account Drill Down

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 the entire charge and payment activity on a particular chart/account for a specified date range.

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

Caveats

  • Voids are excluded.
  • The date range refers to the date of service. Payments may have come in any time after the date of service, including time periods after the end date.

SQL Code: Firebird

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

select at1.date1, at1.cptcode, at1.ins_carrier_code, at1.charge, at1.units, at1.trnsxno, at2.ins_paid, at2.pt_paid from
(select date1, cptcode, ins_carrier_code, charge, trnsxno, units from archive_transactions where archive_flag = 1 and date1 between :Start_date and :enddate and patno = :chart_number and cptcode not in ('1','2','3','4')) at1
left outer join
(select sum(payment) as ins_paid, sum(copayrecd) as pt_paid, txnopaid from
(select copayrecd, payment, txnopaid from archive_transactions where archive_flag = 1 and (copayrecd >= 0.01 or payment >= 0.01))
group by txnopaid) at2
on at2.txnopaid = at1.trnsxno


SQL Code: MySQL

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

select cast(at1.date1 as date) as dos, at1.cptcode, at1.ins_carrier_code, at1.charge, at1.units, at1.trnsxno, at2.ins_paid, at2.pt_paid from
(select date1, cptcode, ins_carrier_code, charge, trnsxno, units from archive_transactions where archive_flag = 1 and date1 between :start_date and :end_date and patno = :chart_number and cptcode not in ('1','2','3','4')) at1
left outer join
(select sum(payment) as ins_paid, sum(copayrecd) as pt_paid, txnopaid from
(select copayrecd, payment, txnopaid from archive_transactions where archive_flag = 1 and (copayrecd >= 0.01 or payment >= 0.01)) t1
group by txnopaid) at2
on at2.txnopaid = at1.trnsxno