Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Query Help

Author  Topic 

mikeallenbrown
Yak Posting Veteran

72 Posts

Posted - 2014-08-14 : 11:50:45
The problem with this query is that if the "PrimaryOrSecondary" is blank or null then the entire record doesn't show. What I need is for the record to show regardless and if there is primary insurance entered show that data otherwise it should be blank.


SELECT Patient.MRNum, Patient.Compined, Patient.DOB, Patient.Sex, PatientStatus.Date, PatientStatus.DischargedDate, PatientStatus.Status, Patient.ClientID, Client.ClientName, PatientInsurance.InsuranceNumber, PatientInsurance.PrimaryOrSecondary, contact.CompanyName 
FROM Client Client
INNER JOIN (Patient Patient
FULL OUTER JOIN PatientStatus PatientStatus
ON Patient.MRNum = PatientStatus.MRNum2 AND Patient.ClientID = PatientStatus.Clientid2
FULL OUTER JOIN (PatientInsurance PatientInsurance
INNER JOIN contact contact
ON PatientInsurance.InsuranceID = contact.id )
ON Patient.ID = PatientInsurance.PatientID )
ON Client.ID = Patient.ClientID
WHERE PatientStatus.RptMonth = 7 AND PatientStatus.RptYear = 2014 AND PatientInsurance.PrimaryOrSecondary = 'Primary' AND Patient.ClientID = 5001


This is the result I get now...


This is the result I want...


Mike Brown

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-08-14 : 12:43:55
Your WHERE clause has this:


PatientInsurance.PrimaryOrSecondary = 'Primary'


which will exclude rows not meeting that condition. If you want to see those rows anyway, why not remove the condition?
Go to Top of Page

mikeallenbrown
Yak Posting Veteran

72 Posts

Posted - 2014-08-14 : 14:30:13
If there is no insurance entered at all the record doesn't appear at all...I still need it to show up. If there is a "Primary" insurance record then that shows as well.

I'm still a SQL novice so I am unsure how to go about doing this.

Mike Brown
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-08-14 : 14:37:00
remove PatientInsurance.PrimaryOrSecondary = 'Primary' from your WHERE clause. what do you get?
Go to Top of Page
   

- Advertisement -