我正在使用我创建的 SQL 存储参数构建报告。它提取每个唯一编号可能有 1 行或每个唯一编号 2 行的数据。我只想显示只有 1 行的行。
我曾尝试改变可见性,但我最接近的是
=IIF(Fields!uniquenumber.Value = previous(Fields!uniquenumber.value,True,False)
但这隐藏了其中的 1 行,而不是两者。我也尝试在查询中使用 CASE WHEN 来识别是否有超过 1 行,但是当超过 1 行时我仍然无法隐藏。我的查询如下(在这里编辑了几行与我的问题无关的额外标准。在很多情况下,我的 WHERE 语句的第一部分的数据也符合第二部分的标准。
SELECT
Reorders.LastRxNo,
Reorders_1.LastRxNo AS Reorders1LastRxNo,
Rxs_2.RxBatch AS Rxs2RxBatch,
Reorders.FacID,
KeyIdentifiers.GPI,
Reorders.LastFillDt,
Rxs_1.RxBatch as Rxs1RxBatch,
CASE
WHEN (Reorders.LastRxNo<>Reorders_1.LastRxNo) THEN 1
ELSE 0
END AS Duplicate
FROM Reorders
LEFT OUTER JOIN Rxs AS Rxs_1
ON Reorders.LastRXNo = Rxs_1.RxNo
RIGHT OUTER JOIN KeyIdentifiers
ON Reorders.NDC = KeyIdentifiers.NDC
INNER JOIN Patients
ON Reorders.FacID = Patients.FacID
AND Reorders.PatID = Patients.PatID
LEFT OUTER JOIN Reorders AS Reorders_1
ON Reorders.FacID = Reorders_1.FacID
AND Reorders.PatID = Reorders_1.PatID
AND KeyIdentifiers.NDC = Reorders_1.NDC
LEFT OUTER JOIN Rxs AS Rxs_2
ON Reorders_1.LastRxNo = Rxs_2.RxNo
WHERE
Reorders.ProfileOnly = 1
AND Rxs_1.RxBatch IS NULL
AND Reorders.CutOffDt IS NULL
AND Reorders.PackType LIKE 'PHDEF%'
AND Reorders.Auto = 1
AND Reorders.PhRxStatus IS NULL
AND Reorders.LastFillDt > '01/01/2019'
AND (Reorders.LastRxNo = Reorders_1.LastRxNo
OR Reorders.LastRxNo <> Reorders_1.LastRxNo AND Rxs_2.RxBatch IN ('CF','GONE'))
ORDER BY Reorders.FacID, Patients.PatLName, Patients.PatFName
产生类似于:
LastRxNo Reorders1LastRxNo Rxs2RxBatch Duplicate
111 111 null 0
222 222 null 0
222 444 CF 1
在上面的例子中,我只需要看到像第 1 行这样的行。由于“LastRxNo”222 有 2 行,我不想在我的最终报告中看到它。(但是,它被查询,因为当 LastRxNo =222 AND Reorders1LastRxNo = 222 和 Rxs2RxBatch IS NULL 时,如果我没有在我的 WHERE 语句中考虑它,我想。我很高兴以任何可能的方式这样做,无论是在查询或 SSRS 报告中。
替换你的 CASE ... 作为重复
COUNT(*) OVER(PARTITION BY LastRxNo) AS LastRxNoCount
然后
像这样将整个查询包装在另一个选择中......
SELECT * FROM
(
your original query here including the change stated above
) q
WHERE q.LastRxNoCount =1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句