在下面的查询中,发生了什么,第3次连接没有完成。我们正在进行药房匹配,然后显示器显示其他设施中共享同一药房的患者,您能看出为什么会发生这种情况吗?
Insert Into @tblNDC
SELECT ROW_NUMBER() OVER(ORDER BY ID_KEY DESC) AS RN,*
From
(
Select distinct A.PHARMACYNPI,
f.FACILITY_NAME,
ID_KEY,
[BATCH] AS column1,
[IMPORTDATE],
[DATEBILLED],
[RX],
[DATEDISPENSED],
[DAYSUPPLY],
[PAYTYPE],
A.[NPI],
[PHYSICIAN],
[COST],
[QUANTITY],
[MEDICATION],
A.[NDC],
f.FACILITY_ID
FROM [PBM].[T_CHARGES] A
LEFT OUTER JOIN [OGEN].[NDC_M_FORMULARY] B ON A.[NDC] = B.[NDC]
--Left Outer Join PBM.FACILITY f on A.FACILITYNPI = f.FACILITY_NPI
Left Outer Join PBM.PHARMACY_NPI pn on A.PHARMACYNPI = pn.NPI
Inner join PBM.PHARMACY_FACILITY pp on pn.PHARMACY_ID = pp.PHARMACY_ID
Inner Join PBM.FACILITY f on pp.FACILITY_ID = f.FACILITY_ID
Where [STAT] not in (3, 4, 5)
AND [TIER] <> 'T1'
AND f.FACILITY_ID IN
(
select FacilityID from @tblFacility
)
AND f.FACILITY_ID IN
(
SELECT * FROM [PBM].[Split1] (@selectedFacility)
)
答案 0 :(得分:0)
在不知道数据的情况下很难确定,但我的第一个想法是左外连接会给你你可能不想要的连接。
浏览每个联接并将其删除,直到您开始收到狡猾的记录,如果它是突然变得奇怪的第3个,那么我怀疑您有多个设施的ID。