SQL: Find Patients with Insurance Prefix

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 looks for all active patients who have an active insurance policy that contains a specified prefix. The SQL code consists of the prefix ‘ABC’, but it can be altered to find the insurance policy prefix you desire.

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

Caveats

In the third line, 'ABC%' must be changed to properly run this code. You can do one of the following:

  • Change the letters ‘ABC%’ to look for your desired insurance policy prefix.  For example, if you are looking for all patients whose insurance policy number begins with WT3, change the third line to:

where INSURED_ID like 'WT3%' 

  • If you are looking for a sequence of letters or characters that appear anywhere in the insurance policy (not just at the beginning [prefix]), add a % sign to the beginning of the alphanumeric sequence.  For example, if you are looking for patients whose insurance policy includes the sequence 156 anywhere in the policy number, change the third line to:

where INSURED_ID like '%156%' 

SQL Code: Firebird

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

select PATNO,fname,lname,INS_CARRIER_NAME,insured1.INSURED_ID from insured1
inner join register on register.patno = insured1.patno
where insured1.INSURED_ID like 'ABC%'
and status_policy ='ACTIVE'
and status_pat = 'ACTIVE'


SQL Code: MySQL

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

select register.PATNO,fname,lname,INS_CARRIER_NAME,insured1.INSURED_ID from insured1
inner join register on register.patno = insured1.patno
where insured1.INSURED_ID like 'ABC%'
and status_policy ='ACTIVE'
and status_pat = 'ACTIVE'