SELECT X.COURSE,
X.SESSION_NBR,
A.BUSINESS_UNIT,
A.DEMAND_ID,
A.DESCR
FROM PS_CRSE_SESSN_TBL X,
PS_TRN_DEMAND A,
PS_BUDGET_PERIOD E,
PS_BUDGET_BUS_UNIT M
WHERE (A.COURSE = X.COURSE
OR A.COURSE IN (SELECT B.COURSE FROM PS_TRN_CATALOG_TBL B
WHERE B.SUB_CATEGORY_CD IN (SELECT C.SUB_CATEGORY_CD FROM PS_TRN_CATALOG_TBL C
WHERE C.COURSE = X.COURSE)
AND B.CATEGORY_CD IN (SELECT C.CATEGORY_CD FROM PS_TRN_CATALOG_TBL C
WHERE C.COURSE = X.COURSE))
OR A.COURSE IN (SELECT B.COURSE FROM PS_TRN_CATALOG_TBL B
WHERE B.SUB_CATEGORY_CD = 'UNKNOWN'
AND B.CATEGORY_CD IN (SELECT C.CATEGORY_CD FROM PS_TRN_CATALOG_TBL C
WHERE C.COURSE = X.COURSE)))
AND E.BUDGET_PERIOD = A.BUDGET_PERIOD
AND E.EFFDT <= X.COURSE_START_DT
AND E.THRU_DATE >= X.COURSE_END_DT
AND E.BUDGET_PERIOD = M.BUDGET_PERIOD
AND M.BUSINESS_UNIT = A.BUSINESS_UNIT
|