SQL: Simple Charges, Payments, and Adjustments

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 chart number, DOB, claim (invoice) number, date of service, CPT code, insurance code, charge, place of service, diagnosis code(s), payment, and adjustment amounts for the date range you specify.

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

Caveats

  • Voided charges and payments do not appear.
  • “Paid” includes both patient and insurance side payments. The adjustments are split out into insurance and patient side.
  • “Pending” refers to amounts that are still considered receivable. It is computed by subtracting the paid and adjusted amounts from the charge amount.

SQL Code: Firebird

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

select at1.patno, birthdat, at1.invoiceno, at1.date1, at1.cptcode, at1.ins_carrier_code, at1.charge, at1.units, at1.trnsxno, at1.pos, at1.dxcode1, at1.dxcode2, at1.dxcode3, at1.dxcode4, at2.paid, at2.ins_adj, at2.pt_adj, round(charge-paid-ins_adj-pt_adj,2) as pending from
(select date1, patno, invoiceno, cptcode, ins_carrier_code, charge, trnsxno, pos, units, dxcode1, dxcode2, dxcode3, dxcode4 from archive_transactions where archive_flag = 1 and date1 between :Start_date and :enddate and cptcode not in ('1','2','3','4','PLA')) at1
inner join register on register.patno = at1.patno
left outer join
(select round(sum(p),2) as paid, sum(adjustment) as ins_adj, sum(copayadjustment) as pt_adj, txnopaid from
(select copayrecd, payment, copayrecd+payment as p, adjustment, copayadjustment, txnopaid from archive_transactions where archive_flag =1 )
group by txnopaid) at2
on at2.txnopaid = at1.trnsxno
order by patno, invoiceno


SQL Code: MySQL

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

select at1.patno, birthdat, at1.invoiceno, at1.date1, at1.cptcode, at1.ins_carrier_code, at1.charge, at1.units, at1.trnsxno, at1.pos, at1.dxcode1, at1.dxcode2, at1.dxcode3, at1.dxcode4, at2.paid, at2.ins_adj, at2.pt_adj, 
round(charge-paid-ins_adj-pt_adj,2) as pending from
(select date1, patno, invoiceno, cptcode, ins_carrier_code, charge, trnsxno, pos, units, dxcode1, dxcode2, dxcode3, dxcode4 from archive_transactions where archive_flag = 1 and 
date1 between :start_date and :end_date and cptcode not in ('1','2','3','4','PLA')) at1
inner join register on register.patno = at1.patno
left outer join
(select round(sum(p),2) as paid, sum(adjustment) as ins_adj, sum(copayadjustment) as pt_adj, txnopaid from
(select copayrecd, payment, copayrecd+payment as p, adjustment, copayadjustment, txnopaid from archive_transactions where archive_flag =1 ) t1
group by txnopaid) at2
on at2.txnopaid = at1.trnsxno
order by patno, invoiceno