PS Query & SQL

 View Only
  • 1.  Another Query Support Request!

    Posted 4 hours ago

    Hello Friends,

    This is Lidia again. I have another query manager question. 

    We have a request to pull student data, including current enrollment and any future enrollment for the upcoming term (s). The catch is that it must not create duplicate rows.

    Any help is greatly appreciated.

    Lidia



    ------------------------------
    Lidia Anderson
    Manager, Campus Solutions
    Central Washington University
    lidia.anderson@cwu.edu
    ------------------------------
    HEUG ANZ - Brisbane, 9-10 September 2026


  • 2.  RE: Another Query Support Request!

    Posted 4 hours ago

    Can you describe what fields you want in the output and to what level of detail?  If you want one row per student that means some type of consolidation within fields and/or a set of specific columns to hold the information.  What you want in the results will drive how the query will be created.



    ------------------------------
    David Ehrlich
    Senior Business Systems Analyst
    Duke University
    ------------------------------

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

    HEUG ANZ - Brisbane, 9-10 September 2026


  • 3.  RE: Another Query Support Request!

    Posted 4 hours ago

    David,

     

    Are you asking for all fields or only those related to STDNT_CAR_TERM? Assuming STDNT_CAR_TERM only, I need to see the total amount of units per term in individual columns. For example, Fall 2026 (column 1), 12.00 (column 2)

     

    Lidia

     

     




    HEUG ANZ - Brisbane, 9-10 September 2026


  • 4.  RE: Another Query Support Request!

    Posted 3 hours ago
    Lidia,

    If you have a predefined number of terms that you are trying to return, then there are ways that you can populate those values. For example, if you are certain that you will only ever need to look at a maximum of 10 terms, then you could write an expression for each of those 10 terms.

    The obvious issues with this are that you would lose the ability to see that 11th term, and you would also get a lot of unnecessary data, for all of the non-enrolled terms for that person.

    Alternatively, you could use the LISTAGG() function to return any future term with enrollment, but - as David was suggesting - all of the term results would be in a single column. Depending on the use-case, this might be the optimal solution for you.

    Perhaps there is another approach, but these are the solutions that come to my mind - and which one I would use depends on how the data is being used.

    Jeffrie



    --
    Jeffrie Brooks | BUSINESS SYSTEM ANALYST
    UNIVERSITY OF MICHIGAN | INFORMATION AND TECHNOLOGY SERVICES
    734-647-8763 | jedobr@umich.edu



    HEUG ANZ - Brisbane, 9-10 September 2026


  • 5.  RE: Another Query Support Request!

    Posted 2 hours ago
    Edited by Daniel Labrecque 2 hours ago

    Lidia,

    If you don't want to hard code the terms in question, you can you the NTH_VALUE sql function.  I built something out using STDNT_CAR_TERM. You will need to use DISTINCT for the query properties.  NTH_VALUE doesn't care what the field criteria is only its position.

    So for the first expression, I wanted to get the most recent term value:

    NTH_VALUE(A.STRM, 1) OVER (
      PARTITION BY A.EMPLID, A.ACAD_CAREER, A.INSTITUTION
      ORDER BY A.STRM DESC
      ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
    )

    This will give me the most recent term.  When you look at NTH_VALUE(A.STRM, 1), the 1 is the first position.  The order by will give me the STRM in descending order.

    The next expression is using the UNT_TAKEN_FA field:

    NTH_VALUE(A.UNT_TAKEN_FA, 1) OVER (
      PARTITION BY A.EMPLID, A.ACAD_CAREER, A.INSTITUTION
      ORDER BY A.STRM DESC
      ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
    )

    This will give me the UNT_TAKEN_FA that is in the first position and it is ordered by the STRM in descending order.

    For all the other columns, just create a new expression.  Each expression will be identical except the position number changes so NTH_VALUE(A.UNT_TAKEN_FA, 1) becomes NTH_VALUE(A.UNT_TAKEN_FA, 2), NTH_VALUE(A.UNT_TAKEN_FA, 3), NTH_VALUE(A.UNT_TAKEN_FA, 4), etc.

    Below is an example:




    ------------------------------
    Daniel Labrecque
    Oracle Consulting Manager
    Huron Consulting Group
    ------------------------------

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

    HEUG ANZ - Brisbane, 9-10 September 2026


  • 6.  RE: Another Query Support Request!

    Posted 2 hours ago

    Good afternoon Lidia,

    I don't work in CS, but PSQuery is pretty much the same in  HCM...

    The first thing I would recommend is checking the DISTINCT box (if it is available). In PSQuery, this is the equivalent of starting your SQL-statement with "SELECT DISTINCT". You'll find the check box in a funky place in PSQuery. It's in the pop-up window when you click on Properties. This is the same pop-up you use when entering the query name, description, folder, etc. Sometimes the check box will not be available (such as with a Unioned query), but for simple queries it usually is. 

    My other pro-tip is to avoid aggregates until you can get the query to return basic data as a single row per employee. Aggregating fields either from the Fields tab or with SQL operators in Expressions can do weird things to your data.

    And if you find that you are getting multiple rows of data per employee, try deleting one field at a time until you find the one that causes multiple rows. Then, work on that field.

    Hope that helps.



    ------------------------------
    Scott Frey
    Connected Campus CoP Member - Senior Data Analyst-HR Info Systems
    University of Colorado System
    ------------------------------

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

    HEUG ANZ - Brisbane, 9-10 September 2026