SELECT DISTINCT A.EMPLID , A.EMPL_RCD , A.ACA_GRP_ID , A.NAME , A.FIRST_NAME , A.LAST_NAME , A.ACA_MONTH , A.COMPANY , A.ACA_MONTHLY_TOT + CASE WHEN( SELECT T.ACA_MONTHLY_TOT FROM PS_ACA_MONTHLY_TL T WHERE T.EMPLID = A.EMPLID AND T.EMPL_RCD = A.EMPL_RCD AND T.ACA_GRP_ID = A.ACA_GRP_ID AND T.ACA_MONTH = A.ACA_MONTH AND T.COMPANY = A.COMPANY)<> 0 THEN ( SELECT T.ACA_MONTHLY_TOT FROM PS_ACA_MONTHLY_TL T WHERE T.EMPLID = A.EMPLID AND T.EMPL_RCD = A.EMPL_RCD AND T.ACA_GRP_ID = A.ACA_GRP_ID AND T.ACA_MONTH = A.ACA_MONTH AND T.COMPANY = A.COMPANY) ELSE 0.00 END ACA_MONTHLY_AVG, ( SELECT SUM(B.ACA_MONTHLY_TOT) FROM PS_ACA_MONTHLY_JOB B WHERE B.EMPLID = A.EMPLID AND B.ACA_GRP_ID = A.ACA_GRP_ID AND B.COMPANY = A.COMPANY AND B.ACA_MONTH = A.ACA_MONTH) + CASE WHEN( SELECT SUM(T2.ACA_MONTHLY_TOT) FROM PS_ACA_MONTHLY_TL T2 WHERE T2.EMPLID = A.EMPLID AND T2.ACA_GRP_ID = A.ACA_GRP_ID AND T2.COMPANY = A.COMPANY AND T2.ACA_MONTH = A.ACA_MONTH) <> 0 THEN ( SELECT SUM(T2.ACA_MONTHLY_TOT) FROM PS_ACA_MONTHLY_TL T2 WHERE T2.EMPLID = A.EMPLID AND T2.ACA_GRP_ID = A.ACA_GRP_ID AND T2.COMPANY = A.COMPANY AND T2.ACA_MONTH = A.ACA_MONTH) ELSE 0.00 END ACA_MONTHLY_TOT_2, A.ACA_PERIOD FROM PS_ACA_MONTHLY_JOB A
|