PS Query & SQL

 View Only
  • 1.  Querying tree tables like ACAD_ORGANIZATION

    Posted 02-06-2025 06:27 PM

    Hello!
    I am looking for a way to simplify querying trees without repeatedly joining to PSTREENODE for different levels of a tree. 

    Is there an effective way to do this in query?

    For example, we have acad org on the academic plan owner record and sometimes the acad org is at the department level as the owner vs school. I am trying to pull in the school. The parent node of the acad org is not always the school in our setup.

    Thanks in advance!



    ------------------------------
    Cho Kim
    Associate Registrar - Enrollment & Systems Management
    Southern Methodist University
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------
    Alliance 2026 Registration is Open!


  • 2.  RE: Querying tree tables like ACAD_ORGANIZATION

    Posted 02-07-2025 07:47 AM

    Do you mean in PS Query?

     

    You can do "in tree" and then you don't have to do the joins manually to the tree tables.

     

    For example:

     

     

    If I need to look at ranges, I connect directly to the tree records.  A lot of my trees are very basic and is just a list so to speak so if I just need to know if something is in the list, I'll use the in tree or not in tree function.

     

    Is this what you are asking?

     




    Alliance 2026 Registration is Open!


  • 3.  RE: Querying tree tables like ACAD_ORGANIZATION

    Posted 02-07-2025 11:30 AM

    As someone at an institution with a similar setup, I'm going to guess Cho is being asked to report the school associated with each plan (right ?).  We never found a better way to do this than navigating the tree unfortunately, so we created a SQL view to do it for us so that at least we didn't have to manually add it to the PS Query.



    ------------------------------
    Scott Nishizaki
    Developer/Analyst
    Azusa Pacific University
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Registration is Open!


  • 4.  RE: Querying tree tables like ACAD_ORGANIZATION

    Posted 02-07-2025 06:02 PM
    Edited by Cho Kim 02-07-2025 06:02 PM
      |   view attached

    That's correct, Scott. My end goal was to report the school associated with each academic plan. The diagram below depicts how our academic organization structure is laid out. Sometimes there is a "sub-school" folder where querying the parent node information returns the sub-school and not the actual school the academic org resides in. Thanks for the idea about creating a SQL view, curious what that SQL looks like if you can share it!


    I was trying to do what was in the attached slides shared at SCHRUG that eliminates joining to the PSTREENODE over and over again but the example uses HCM data and doesn't illustrate the joins in the screenshots.



    Attachment(s)

    Alliance 2026 Registration is Open!


  • 5.  RE: Querying tree tables like ACAD_ORGANIZATION

    Posted 02-11-2025 11:25 AM

    This SQL was written by my co-worker Scott Douglas, it's a bit complex so let us know if you have questions.

    WITH DATES AS (   
    	SELECT DISTINCT A.EFFDT   
    	FROM SYSADM.PSTREENODE A   
    	WHERE A.TREE_NAME = 'ACAD_ORG_REPORT'   
    	UNION   
    	SELECT DISTINCT B.EFFDT   
    	FROM SYSADM.PS_ACAD_ORG_TBL B 
    )   
    
    , TREE AS (   
    	SELECT DISTINCT 
    		T.TREE_NODE ACAD_ORG   
    		, T.EFFDT   
    		, COALESCE(TRIM(SYS_CONNECT_BY_PATH (CASE WHEN LEVEL = 2 THEN TREE_NODE END  ,' '))  ,' ') AS APU_SCHL_ORG   
    		, COALESCE(TRIM(SYS_CONNECT_BY_PATH (CASE WHEN LEVEL = 3 THEN TREE_NODE END  ,' '))  ,' ') AS APU_SCH2_ORG   
    		, LTRIM(SYS_CONNECT_BY_PATH (TREE_NODE  ,' > ')  ,' > ') AS HIERARCHY   
    		, LEVEL LVL   
    	FROM SYSADM.PSTREENODE T   
    	WHERE TREE_NAME = 'ACAD_ORG_REPORT' 
    	START WITH TREE_NODE = 'APU' 
    	CONNECT BY PRIOR TREE_NODE = PARENT_NODE_NAME   
    		AND TREE_NAME = PRIOR TREE_NAME   
    		AND EFFDT = PRIOR EFFDT 
    )   
    
    SELECT DISTINCT 
    	MAIN.ACAD_ORG   
    	, D.EFFDT   
    	, MAIN.DESCR   
    	, MAIN.DESCRFORMAL   
    	, COALESCE(TRIM(MAIN.APU_SCHL_ORG)  , MAIN.ACAD_ORG) AS APU_SCHL_ORG   
    	, COALESCE(SCHL.DESCR  , 'Azusa Pacific University') AS APU_SCHL_DESCR   
    	, COALESCE(SCHL.DESCRFORMAL  , 'Azusa Pacific University') AS APU_SCHL_DESCRFRML   
    	, CASE WHEN SCH2.IS_SCHOOL = 'Y' THEN MAIN.APU_SCH2_ORG END AS APU_SCH2_ORG   
    	, CASE WHEN SCH2.IS_SCHOOL = 'Y' THEN SCH2.DESCR END AS APU_SCH2_DESCR   
    	, CASE WHEN SCH2.IS_SCHOOL = 'Y' THEN SCH2.DESCRFORMAL END AS APU_SCH2_DESCRFRML   
    	, MAIN.LVL   
    	, MAIN.HIERARCHY   
    FROM DATES D 
    JOIN (   
    	SELECT DISTINCT 
    		ORG1.ACAD_ORG   
    		, ORG1.EFFDT   
    		, ORG1.DESCR   
    		, ORG1.DESCRFORMAL   
    		, T1.APU_SCHL_ORG   
    		, T1.APU_SCH2_ORG   
    		, T1.LVL   
    		, T1.HIERARCHY   
    	FROM (   
    		SELECT 
    			ORG.ACAD_ORG   
    			, D1.EFFDT   
    			, ORG.EFFDT AS ORG_EFFDT   
    			, ORG.DESCR   
    			, ORG.DESCRFORMAL   
    			, ROW_NUMBER () OVER (PARTITION BY ORG.ACAD_ORG  , D1.EFFDT   ORDER BY ORG.EFFDT DESC) RN   
    		FROM DATES D1 
    		JOIN SYSADM.PS_ACAD_ORG_TBL ORG 
    			ON ORG.EFFDT <= D1.EFFDT 
    	) ORG1 
    	JOIN TREE T1 
    		ON ORG1.ACAD_ORG = T1.ACAD_ORG   
    		AND ORG1.EFFDT = T1.EFFDT   
    	WHERE ORG1.RN = 1 
    ) MAIN 
    	ON D.EFFDT = MAIN.EFFDT 
    LEFT JOIN SYSADM.PS_ACAD_ORG_TBL SCHL 
    	ON MAIN.APU_SCHL_ORG = SCHL.ACAD_ORG 
    LEFT JOIN (   
    	SELECT 
    		ACAD_ORG  
    		, DESCR  
    		, DESCRFORMAL  
    		, EFFDT   
    		, CASE WHEN 
    			(DESCRFORMAL LIKE '%School%' OR DESCRFORMAL = 'Azusa Pacific Seminary')  
    			AND DESCRFORMAL NOT LIKE '%Dept%'   
    			AND DESCRFORMAL NOT LIKE '%Department%'   
    			AND SUBSTR (DESCRFORMAL  , - 3) NOT IN (' UG'  , ' GR'  , ' UP'  , ' GH'  , ' ND') 
    		THEN 'Y' 
    		END AS IS_SCHOOL   
    	FROM SYSADM.PS_ACAD_ORG_TBL 
    ) SCH2 
    	ON MAIN.APU_SCH2_ORG = SCH2.ACAD_ORG   
    WHERE 
    	( SCHL.EFFDT = (SELECT MAX (O2.EFFDT)   
    					FROM SYSADM.PS_ACAD_ORG_TBL O2   
    					WHERE SCHL.ACAD_ORG = O2.ACAD_ORG   
    						AND O2.EFFDT <= D.EFFDT)   
    		OR SCHL.EFFDT IS NULL)   
    	AND ( SCH2.EFFDT = (SELECT MAX (O3.EFFDT)   
    						FROM SYSADM.PS_ACAD_ORG_TBL O3   
    						WHERE SCH2.ACAD_ORG = O3.ACAD_ORG   
    						AND O3.EFFDT <= MAIN.EFFDT)   
    		OR SCH2.EFFDT IS NULL)   
    ORDER BY MAIN.ACAD_ORG, D.EFFDT DESC


    ------------------------------
    Scott Nishizaki
    Developer/Analyst
    Azusa Pacific University
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Registration is Open!


  • 6.  RE: Querying tree tables like ACAD_ORGANIZATION

    Posted 02-11-2025 02:17 PM

    Scott Nishizaki beat me to it! The SQL he shared is probably the 5th iteration over the past few years, as I attempted to learn hierarchical queries to loop through the PSTREENODE table and adjust for however many levels we end up having on the tree. A few things to point out:

    The "DATES" common table expression is just used to get a list of all effective dates where either the ACAD_ORG_TBL changed, or the tree that we use for tracking acad structure over time. You'll notice that we created a separate ACAD_ORG_REPORT tree for this historical reporting, whereas we don't try to retain the full effective-dated history on the delivered ACAD_ORGANIZATION tree used for security.

    Our departments are extremely granular, sometimes split by Career code, so we are not joining Subjects to the tree. We just use the "dynamic flag".

    Some schools are nested within colleges and some schools are not, so in order to find top-level college/school and second-level college/school where applicable, we have to test the descriptions against naming conventions... this requires some maintenance over time, but it's worth it for us in the long run.

    Basically if you were to replace the tree name with yours (probably ACAD_ORGANIZATION)

    WHERE TREE_NAME = 'ACAD_ORG_REPORT' 

    And update your root tree node here
    START WITH TREE_NODE = 'APU'

    Then you should at least get some data out, and you can start tweaking with the rest of the hard-coded stuff, etc. Have fun! :)



    ------------------------------
    Scott Douglas
    Sr. Business Systems Analyst, Student Information Systems
    Azusa Pacific University
    ------------------------------

    Alliance 2026 Registration is Open!


  • 7.  RE: Querying tree tables like ACAD_ORGANIZATION

    Posted 02-12-2025 03:19 PM

    Hi Scott,

    Thank you for sharing this.

    This has lead me to the best sql that I have, to get a list of all of the navigations in peoplesoft.

    --full path to all ps navigations, hidden or not
    select replace(sys_connect_by_path (portal_label, ' > '), ' > Root > ', '') pia_navigation,
           portal_label, portal_objname, portal_prntobjname, portal_uri_seg1, portal_uri_seg2, portal_uri_seg3
      from psprsmdefn a
     where portal_name = 'EMPLOYEE'
       and portal_reftype  = 'C' 
    connect by --nocycle 
            prior portal_objname = portal_prntobjname
              and portal_name = prior portal_name
              and prior portal_reftype = 'F'  /* the prior portal reference type should always be a folder and not a content reference type */
              start with portal_objname = 'PORTAL_ROOT_OBJECT'
    order by 1
    ;



    ------------------------------
    Alexei Tetenov
    Software Engineer
    Rochester Institute of Technology
    ------------------------------

    Message from the HEUG Marketplace:
    ------------------------------
    Find, Review, and Engage with Higher Education-focused solution providers, products, and services using the HEUG Marketplace.
    ------------------------------

    Alliance 2026 Registration is Open!