问题
I'm attempting to build a report in PeopleSoft's Query Manager that has future and current employees on it. I want to be able to find the employees who do not have leave plans, specifically 50 and 52. I thought I was on the right track with the following BUT after auditing my report it is bringing in people who HAVE 50 and 52. I think it has to do with the subquery (SQL below).
Here are some pictures of query manager:
SELECT DISTINCT B.COMPANY, A.EMPLID, A.NAME, B.FULL_PART_TIME, B.REG_TEMP, C.DESCR, D.PLAN_TYPE, (CASE WHEN B.REG_TEMP = 'T' THEN '' WHEN C.DESCR = 'Intern' THEN '' WHEN C.DESCR = 'PenFed Intern' THEN '' ELSE 'Check records/give Leave' END), CONVERT(CHAR(10),SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10),121)), (CONVERT(CHAR(10),SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10),121)), (CONVERT(CHAR(10),SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10),121))
FROM (PS_PERSONAL_DATA A LEFT OUTER JOIN (PS_LEAVE_PLAN D INNER JOIN PS_EMPLMT_SRCH_QRY D1 ON (D.EMPLID = D1.EMPLID AND D.EMPL_RCD = D1.EMPL_RCD AND D1.OPRID = 'XXXXXXXX' )) ON A.EMPLID = D.EMPLID ), PS_PFC_JOB_VW B, PS_JOBCODE_TBL C, PS_SET_CNTRL_REC C2
WHERE ( C.JOBCODE = B.JOBCODE
AND C2.SETCNTRLVALUE = B.BUSINESS_UNIT
AND C2.RECNAME = 'JOBCODE_TBL'
AND C2.SETID = C.SETID
AND ( A.EMPLID = B.EMPLID
AND ( B.EFFDT =
(SELECT MAX(B_ED.EFFDT) FROM PS_PFC_JOB_VW B_ED
WHERE B.EMPLID = B_ED.EMPLID
AND B.EMPL_RCD = B_ED.EMPL_RCD
AND B_ED.EFFDT <= SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10))
AND B.EFFSEQ =
(SELECT MAX(B_ES.EFFSEQ) FROM PS_PFC_JOB_VW B_ES
WHERE B.EMPLID = B_ES.EMPLID
AND B.EMPL_RCD = B_ES.EMPL_RCD
AND B.EFFDT = B_ES.EFFDT)
OR ( B.EFFDT =
(SELECT MIN(B_ED.EFFDT) FROM PS_PFC_JOB_VW B_ED
WHERE B.EMPLID = B_ED.EMPLID
AND B.EMPL_RCD = B_ED.EMPL_RCD
AND B_ED.EFFDT >= SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10))
AND B.EFFSEQ =
(SELECT MAX(B_ES.EFFSEQ) FROM PS_PFC_JOB_VW B_ES
WHERE B.EMPLID = B_ES.EMPLID
AND B.EMPL_RCD = B_ES.EMPL_RCD
AND B.EFFDT = B_ES.EFFDT)
AND B.ACTION IN ('HIR','REH','REI')))
AND B.EMPL_STATUS IN ('A','L','P')
AND B.PER_ORG = 'EMP'
AND C.EFFDT =
(SELECT MAX(C_ED.EFFDT) FROM PS_JOBCODE_TBL C_ED
WHERE C.SETID = C_ED.SETID
AND C.JOBCODE = C_ED.JOBCODE
AND C_ED.EFFDT <= B.EFFDT)
AND A.EMPLID NOT IN (SELECT E.EMPLID
FROM PS_LEAVE_PLAN E, PS_EMPLMT_SRCH_QRY E1
WHERE E.EMPLID = E1.EMPLID
AND E.EMPL_RCD = E1.EMPL_RCD
AND E1.OPRID = 'XXXXXXXX'
AND ( E.EFFDT =
(SELECT MAX(E_ED.EFFDT) FROM PS_LEAVE_PLAN E_ED
WHERE E.EMPLID = E_ED.EMPLID
AND E.EMPL_RCD = E_ED.EMPL_RCD
AND E.PLAN_TYPE = E_ED.PLAN_TYPE
AND E.BENEFIT_NBR = E_ED.BENEFIT_NBR
AND E_ED.EFFDT <= SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10))
AND ( E.PLAN_TYPE = '50'
OR E.PLAN_TYPE = '52') )) ))
Where am I going wrong here?
来源:https://stackoverflow.com/questions/55639168/peoplesoft-subquery-not-picking-up-correct-leave-plans