Patients with Appointments Today and a Significant Balance, Sorted by Site and Provider

List the names of patients with balances of $120 or more, sorted by site and provider, who are scheduled to be seen on the day the query is run.

SELECT
  a.sitename+' ('+a.sitecode+')' AS "site",
  (a.provlname+', '+a.provfname+' ('+provcode+')') AS "provider",
  a.ptfullname,
  a.id,
  b.ptbalance
FROM
  sos.rv_appts a
  JOIN sos.pt_noninsbalance b ON a.ptnum = b.ptnum
WHERE
  b.ptbalance >= 120
  AND a.cancelflag = 0
  AND a.apptdate = TODAY()
ORDER BY
  "site","provider",a.ptfullname,a.id

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.