Patients by Last Four Digits of Social Security Number

Recently we had an audit done by an outside agency that used the last 4 digits of the SS# to identify the
patient charges they chose to audit. We have a need to take a look at several of those charts, but the
only identifying data we now have is the last 4 SS# digits. How can I retrieve the patients with just this
information?
The following query should provide you with what you need. Just replace 1234 in the last line with the
digits you want to search. Don't neglect the single quotes around the number:
SELECT
   lastname, 
   firstname, 
   id, 
   socsec
FROM
   sos.patients
WHERE
   RIGHT(socsec,4) = '1234'
If you have a list of numbers you would like to do in a single shot, you can modify it as follows:
SELECT
   lastname, 
   firstname, 
   id, 
   socsec, 
   RIGHT(socsec,4) as "last4"
FROM
   sos.patients
WHERE
   last4 IN ('1234','5678','2468','4321')
or, for a complete list of patients, sorted by the last four digits:
SELECT
   RIGHT(socsec,4) as "last4", 
   lastname, 
   firstname, 
   id, 
   socsec
FROM
   sos.patients
ORDER BY 
   last4

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.