Patients with Primary Provider and Primary Dx, Sorted by Provider Code

This query demonstrates the use of IF expressions to display “None” rather than “NULL” wherever there is no primary provider or dx.

Select All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
SELECT
   Patients.LastName,
   Patients.FirstName,
   Patients.ID,
 
   IF Patients.ProviderNum IS NULL
     THEN 'None'
     ELSE (Providers.ProvCode +': '+ Providers.ProvLName +', ' + Providers.ProvFName)
   END IF AS "Provider",
 
   IF Dx.DxCode IS NULL
     THEN 'None'
     ELSE Dx.DxCode
   END IF AS "PrimaryDx"
FROM
   Patients
   LEFT OUTER JOIN Providers ON Patients.ProviderNum = Providers.ProviderNum
   LEFT OUTER JOIN PtCSU ON Patients.PtNum = PtCSU.PtNum
LEFT OUTER JOIN Dx ON PtCSU.Dx1 = Dx.DxNum
WHERE
   Patients.LicNum = 101
   AND Patients.Flag = 0
   AND Patients.DischargeDate IS NULL
   AND PtCSU.TypeFlag = 'D'
ORDER BY
   Providers.ProvCode,Patients.LastName,Patients.FirstName,Patients.id
; OUTPUT TO c:\sos\provptdxlist.html FORMAT HTML

Leave a Reply

  

  

  

* Copy this password:

* Type or paste password here:

1,023 Spam Comments Blocked so far by Spam Free Wordpress

You can use these HTML tags

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