Posted By

lonergan123 on 09/11/09


Tagged

Allergy Interactions


Versions (?)

Allergy / Allergen Counts


 / Published in: SQL
 

Return counts for each drug / drug category allergen

  1. SELECT Allergen1.Code, Allergen1.TypeCode, Allergen1.Description, Allergen1.ExternalDrugCode, Counts.AllergyCount
  2. FROM CV3Allergen Allergen1
  3. INNER JOIN
  4. (SELECT Allergen.GUID, Count(NULLIF(Allergy.AllergenGUID,0)) AllergyCount
  5. FROM CV3Allergen Allergen
  6. LEFT JOIN CV3AllergyDeclaration Allergy
  7. ON Allergy.AllergenGUID = Allergen.GUID
  8. AND Allergy.STATUS = 'Active'
  9. AND Allergen.TypeCode IN ('Drug', 'Drug Category')
  10. GROUP BY Allergen.GUID) Counts
  11. ON Allergen1.GUID = Counts.GUID
  12. ORDER BY 5 DESC, 1

Report this snippet  

You need to login to post a comment.