SELECT N.APN_NI,
N.START_TIME_UTC_OFFSET,
CASE
WHEN 0 = :GUI_FILE_SOURCE THEN
(SELECT F.FILENAME
FROM IB_NRT_FILELIST F
WHERE N.NRT_FILE_ID = F.FILE_ID(+))
ELSE
(SELECT M.FILE_NAME
FROM IB_FMS_FILELIST M
WHERE N.FILE_ID = M.FILE_ID(+))
END AS FILENAME
FROM &CDR_TABLE& N,
IB_EVENT_STATE S,
IB_ERR_TYPE ET,
IB_PARTNER P
WHERE 1 = 1
AND N.ERR_TYPE_ID = ET.ERR_TYPE_ID(+)
AND N.STATE = S.STATE(+)
AND N.PARTNER_ID = P.PARTNER_ID(+)