Active Patients Who Have Turned 18 During Treatment

SELECT
COALESCE(b.provcode,'None') AS "Primary Prov",
a.lastname,
a.firstname,
a.ID,
DATEDIFF(year,DOB,intakedate) AS "Age At Intake",
DATEDIFF(year,DOB,CURRENT DATE) AS "Age Now"
FROM
sos.patients a
JOIN sos.providers b ON a.providernum = b.providernum
WHERE
flag = 0   /*active patient */
AND dischargedate IS NULL   /*no discharge date has been entered */
AND "Age At Intake" < 18
AND "Age Now" >= 18
ORDER BY "Primary Prov", a.lastname, a.firstname, a.id

Leave a Reply

Your email address will not be published. Required fields are marked *

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.