List of Clients Who Turned 18 While in Treatment

​I would like to generate a list of clients who turned 18 while in treatment with us?

 

This is actually a pretty simple query. You would just have to identify everyone who was younger than 18 on their intake date, and older than 17 before being discharged.

SELECT
  lastname  AS "Last Name",
  firstname AS "First Name",
  id,
  intakedate,
  dischargedate
FROM
  sos.patients
WHERE
  sos.AGEINYEARS(dob,intakedate) < 18 AND sos.AGEINYEARS(dob,COALESCE(dischargedate,today())) > 17
ORDER BY 
  lastname,firstname, 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.