Wyrzeźbiłem coś takiego gdyby ktoś potrzebował aby poszukać przed wysyłką do NFZ zdublowane procedury
SELECT
EPD.NEPD, count(*)
FROM
EPD
LEFT JOIN KNK ON
KNK.NINS_EPD = EPD.NINS
AND KNK.NEPD = EPD.NEPD
LEFT JOIN PRD ON
PRD.NINS_KNK = KNK.NINS AND
PRD.NKNK = KNK.NKNK AND
(EXTRACT (YEAR FROM PRD.DTDO) = :Rok AND
EXTRACT (MONTH FROM PRD.DTDO) <= :Miesiac)
WHERE
EPD.WERS > 0 AND
PRD.AKTW ='T' AND
( ( (EXTRACT (YEAR FROM EPD.DTDO) = :Rok AND
EXTRACT (MONTH FROM EPD.DTDO) <= :Miesiac)
OR
EPD.DTDO IS NULL
)
OR
( (EXTRACT (YEAR FROM EPD.DTOD) = :Rok AND
EXTRACT (MONTH FROM EPD.DTOD) <= :Miesiac)
)
OR
( ( EXTRACT (YEAR FROM EPD.DTOD) = :Rok)
AND
( EXTRACT (YEAR FROM EPD.DTDO) = :Rok AND
EXTRACT (MONTH FROM EPD.DTDO) <= :Miesiac)
)
)
/* pierwszorazowe */
AND PRD.NBUM_JDN <>'501280000001'
GROUP BY NEPD
HAVING count(*)>1