If InsuranceDetails can be null, you need to use a LEFT JOIN to join your tables together.
SELECT
ipd.InPatientID,
ipd.Fname+' ' +ipd.LName as 'Patient Name' , -- this line is dangerous if name(s) can be null
ipd.Gender,
ipd.BirthDate,
ipd.AccType as 'Account Type',
ipd.Minor,
ipg.GFName+' ' +ipg.GLName as 'Guardian name', -- same here
ipd.Insured,
ipi.Insurance1,
ipi.Policy1,
ipi.GroupNo1,
ipi.Guarantor,
ipi.Employer
from
HMS.dbo.PatientDetails ipd
inner join -- inner join means all conditions in "on" must be true
HMS.dbo.ParentDetails ipg
on
ipd.InPatientID = ipg.InPatientID
left join -- left join means the "on" can be true or null for ipi (right of the join)
HMS.dbo.InsuranceDetails ipi
on
ipd.InPatientID = ipi.InPatientID
darkagn
Nearly a Posting Virtuoso
1,223 posts since Aug 2007
Reputation Points: 404
Solved Threads: 211
Skill Endorsements: 15
Question Answered as of 1 Year Ago by
darkagn
and
seslie