Hello,
I am trying to construct a query across 5 tables but primarily 3
tables. Plan, Provider, ProviderLocatio n are the three primary tables
the other tables are lookup tables for values the other tables.
PlanID is the primary in Plan and
Plan Provider ProviderLocatio n Lookups
-------- ---------- ---------------- -----------
PlanID ProviderID ProviderID LookupType
PlanName PlanID ProviderStatus LookupKey
RegionID LastName ... LookupValue
.... FirstName ...
Given a PlanID I want all the Providers with a ProviderStatus = 0
I can get the query to work just fine if there are records but what I
want is if there are no records then I at least want one record with
the Plan information. Here is a sample of the Query:
SELECT pln.PlanName, pln.PlanID, l3.LookupValue as Region,
p.ProviderID, p.SSNEIN, pl.DisplayLocat ionOnPCP,
pl.NoDisplayDat e, pl.ProviderStat us, pl.InvalidDate,
l1.LookupValue as ReasonMain, l2.LookupValue as ReasonSub,
pl.InvalidData
FROM Plans pln
INNER JOIN Lookups l3 ON l3.LookupType = 'REGN'
AND pln.RegionID = l3.Lookupkey
left outer JOIN Provider p ON pln.PlanID = p.PlanID
left outer JOIN ProviderLocatio n pl ON p.ProviderID = pl.ProviderID
left outer JOIN Lookups l1 ON l1.LookupType = 'PLRM'
AND pl.ReasonMain = l1.LookupKey
left outer JOIN Lookups l2 ON l2.LookupType = 'PLX1'
AND pl.ReasonSub = l2.Lookupkey
WHERE pln.PlanID = '123456789' AND pl.ProviderStat us = 0
ORDER BY p.PlanID, p.ProviderID, pl.SiteLocation Num
I know the problew the ProviderStatus on the Where clause is keeping
any records from being returned but I'm not good enough at this to
another select.
Can anybody give me some suggestions?
Thanks
David