Write effective-dated SQL
Effective-dated SQL is where PeopleSoft queries most often go wrong: a subquery that misses a key,
a forgotten EFFSEQ, or a department description taken from the wrong row. With AI Assist, the LLM
looks up the keys of every record before it writes the query, so the correlations come from your
definitions, not from memory.
You’ll use: describe_record,
get_translate_values, and optionally
run_select.
Write SQL for Oracle that counts active employees by department,with each department's current description, as of today.What happens
Section titled “What happens”-
describe_recordforJOBreturns its keys:EMPLID,EMPL_RCD,EFFDT, andEFFSEQ. Because bothEFFDTandEFFSEQare keys, the current row needs two subqueries: the latest date, then the latest sequence on that date. The field list also includesSETID_DEPT, the setID of the employee’s department. -
describe_recordforDEPT_TBLreturns its keys:SETID,DEPTID, andEFFDT. The department’s current row needs its own effective-date subquery, joined throughSETID_DEPT. -
get_translate_valuesforEMPL_STATUSreturns the status codes, so the LLM can decide which ones count as active, and tell you what it decided. -
run_select, if your administrator allowsPS_JOBandPS_DEPT_TBL, runs the query so the LLM can check that the numbers look reasonable before it hands you the SQL.
What you get
Section titled “What you get”SELECT J.DEPTID, D.DESCR, COUNT(DISTINCT J.EMPLID) AS HEADCOUNT FROM PS_JOB J JOIN PS_DEPT_TBL D ON D.SETID = J.SETID_DEPT AND D.DEPTID = J.DEPTID AND D.EFFDT = (SELECT MAX(D1.EFFDT) FROM PS_DEPT_TBL D1 WHERE D1.SETID = D.SETID AND D1.DEPTID = D.DEPTID AND D1.EFFDT <= SYSDATE) WHERE J.EFFDT = (SELECT MAX(J1.EFFDT) FROM PS_JOB J1 WHERE J1.EMPLID = J.EMPLID AND J1.EMPL_RCD = J.EMPL_RCD AND J1.EFFDT <= SYSDATE) AND J.EFFSEQ = (SELECT MAX(J2.EFFSEQ) FROM PS_JOB J2 WHERE J2.EMPLID = J.EMPLID AND J2.EMPL_RCD = J.EMPL_RCD AND J2.EFFDT = J.EFFDT) AND J.EMPL_STATUS IN ('A', 'L', 'P') GROUP BY J.DEPTID, D.DESCR ORDER BY J.DEPTIDAlong with the query, the LLM explains its choices:
- Active means
EMPL_STATUSA (Active), L (Leave of Absence), or P (Leave With Pay). If your organization defines active employees byHR_STATUSinstead, say so.- The
JOBsubqueries correlate onEMPLIDandEMPL_RCD, the keys beforeEFFDT, andEFFSEQpicks the last change made on the current date.COUNT(DISTINCT J.EMPLID)counts people, not jobs. An employee with two active employment records, whichEMPL_RCDnumbers, would otherwise count twice.- The department join goes through
SETID_DEPT, because departments are keyed by setID.
Check the answer
Section titled “Check the answer”- Compare with PeopleSoft Query. Build the same count in PeopleSoft Query, which adds effective-date criteria to effective-dated records for you, and compare the totals.
- Spot-check an employee who has several job rows on the same date: open them in Job Data and confirm the query picks the row you’d expect.
- Check the plan before you use the query in a scheduled report, since correlated subqueries on
PS_JOBcan be expensive on large systems.
Go further
Section titled “Go further”- “Write the same query for SQL Server.”
- “Rewrite it for an Application Engine SQL action, with
%CurrentDateInand%EffDtCheck.” - “Add each department’s manager.”
- “Count headcount as of the last day of last quarter instead of today.”
