PS Query & SQL

 View Only
Expand all | Collapse all

What's your favorite expression, case statement, trick?

  • 1.  What's your favorite expression, case statement, trick?

    Posted 16 days ago

    What's your favorite trick, case statement, expression in SQL (or PS Query)?  If you have a favorite trick (or treat), please share it!

    Mine is still the one that Jeffrie Brooks shared in a FA post awhile back to get your sum totals to stop multiplying by the number of rows of data coming back.  I've been using it ever since and I LOVE it.  Thank you, Jeffrie!

    SUM(A.OFFER_AMOUNT)*COUNT(DISTINCT A.EMPLID || A.INSTITUTION || A.AID_YEAR || A.ITEM_TYPE || A.ACAD_CAREER)/COUNT(*)

    Since this was on a different forum, I'm copying Jeffrie's total response below instead of linking to the post:  

    So this solution is a bit unconventional but it has worked for me for a couple years now with our FA tables. 
    As you mentioned the amounts are multiplied by the number of rows being rolled up by the aggregate, so what we need to do is come up with the math that divides it by that same number again. After quite a bit of work, I came up with the following statement that seems to accomplish this for us. This example uses STDNT_AWARDS - which is important because the KEY fields play a big role in this.
    SUM(A.OFFER_AMOUNT)*COUNT(DISTINCT A.EMPLID || A.INSTITUTION || A.AID_YEAR || A.ITEM_TYPE || A.ACAD_CAREER)/COUNT(*)
    So what is it doing? Its taking the SUM that you've been stuck with and DIVIDES that number by each row in the QUERY - - - "/COUNT(*)"
    That number actually ends up being too small. So we need to take that number and multiply it by the distinct key fields that are on the table that we want the SUM. - - - *COUNT(DISTINCT A.EMPLID || A.INSTITUTION || A.AID_YEAR || A.ITEM_TYPE || A.ACAD_CAREER). The result should be what you are looking for.
    With different tables, you just replace the concatenated KEY fields.
    For STDNT_AWRD_DSB, the expression becomes: SUM(A.OFFER_BALANCE)*COUNT(DISTINCT A.EMPLID || A.INSTITUTION || A.AID_YEAR || A.ITEM_TYPE || A.ACAD_CAREER || A.DISBURSEMENT_ID)/COUNT(*)
    For STDNT_CAR_TERM it could look like SUM(A.UNT_TAKEN_PRGRSS)*COUNT(DISTINCT A.EMPLID || A.INSTITUTION || A.ACAD_CAREER || A.STRM)/COUNT(*)

    It has worked really well as a work-around for me, with these tables and in our system. I would strongly recommend validating the data when you run it, especially if you are trying to apply this solution to other tables.


    ------------------------------
    Dana Pawlowicz
    Business Systems Analyst Sr - ERP
    University of Cincinnati
    ------------------------------

    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: What's your favorite expression, case statement, trick?

    Posted 16 days ago

    My favorite is the sly way you can add a list of EMPLID's from an expression.

     

    What you do is manually add a test like this and finish it off with the statement:  AND '1'

     

    A.EMPLID IN ('12345', '12354', '45678')

    AND '1'

     

    Then you add it to your criteria and make it equal to 1:

     

    This "tricks" the system into thinking this is two lines of criteria:

     

    SELECT A.EMPLID, A.AID_YEAR
      FROM PS_STDNT_AID_ATRBT A
      WHERE (  A.EMPLID IN ('12345', '12354', '45678')
    AND '1'
    = '1')

     

    This trick has saved me from having to enter 200 EMPLID's for a query and instead I can grab them from a text editor/spreadsheet and get what I want.

     

     

     

     

     

    Scott Cho

    PeopleSoft Campus Solutions Consultant

    630/384-9711

     

     




    Alliance 2026 Registration is Open!


  • 3.  RE: What's your favorite expression, case statement, trick?

    Posted 16 days ago

    love this one, and I learned it from you, Scott! But then at this year's Alliance, I mentioned it, and some delightful soul (whose name I have shamefully forgotten....please identify yourself if you're reading this!) told me you can use "ANY" instead to make it simpler. All you have to do is set EMPLID = [an expression]. The expression text is ANY('10000001','10000002','1000003') except of course you use real EMPLIDs. Then you can skip the "and 1 = 1" bit!



    ------------------------------
    Timothy Krug
    Consulting Manager
    Huron Consulting Group
    ------------------------------

    Alliance 2026 Registration is Open!


  • 4.  RE: What's your favorite expression, case statement, trick?

    Posted 11 days ago

    I use this all the time and have screamed it from the rooftops at my university, but I learned it from Robert Fogarty at Alliance a couple years ago. It would have been such a great tool when implementing for testing.

     

    Morgan Andres
    Senior Business Systems Analyst

    Student Information Services and Systems (SISS)

    Duke University

    1121 West Main St., Suite 2200

    Durham, NC 27701

    E-mail: morgan.andres@duke.edu

     




    Alliance 2026 Registration is Open!


  • 5.  RE: What's your favorite expression, case statement, trick?

    Posted 11 days ago
    The complimentary expression for not in list is

    <>  ALL('10000001','10000002','1000003')

    Bob
    --
    Bob Fogarty
    LionPATH - Reporting Team Lead
    The Pennsylvania State University



    Alliance 2026 Registration is Open!


  • 6.  RE: What's your favorite expression, case statement, trick?

    Posted 3 days ago

    Speaking of ANY()/ALL(), does anyone know if it is possible to use a prompt to pass the list of values.   I've tried a few things, but nothing worked.

    So, Instead of ANY('11111111','22222222',...), something like ANY(:1).  Can it be done?



    ------------------------------
    Kendall Vance
    IT Technical Associate for Financial Aid Reporting
    Northern Illinois 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!


  • 7.  RE: What's your favorite expression, case statement, trick?

    Posted 3 days ago
      |   view attached

    It is. But the amount of values you can pass is really small due to size you can make the prompt.

     

    This presentation had a different way to do the "list of ids" and they have slides on doing it with a prompt.  Starts on slide 15.

     

    But, maybe with multiple optional prompts you can get a decent size list. 

     

     

     




    Alliance 2026 Registration is Open!


  • 8.  RE: What's your favorite expression, case statement, trick?

    Posted 3 days ago

    Bob Fogarty does make a slight mention of it as in the thread.  I think it is fantastic that you can do that.  His example was IDs, but there is no reason it can't be other fields as needed.



    ------------------------------
    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.
    ------------------------------

    Alliance 2026 Registration is Open!


  • 9.  RE: What's your favorite expression, case statement, trick?

    Posted 3 days ago

    Thanks! This session shows the one that I called "Manual Unpivot", they say "Flatten" and use Max() rather than Sum().   Good chance this is where I stole the idea,.... looks familiar.



    ------------------------------
    Kendall Vance
    IT Technical Associate for Financial Aid Reporting
    Northern Illinois 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!


  • 10.  RE: What's your favorite expression, case statement, trick?

    Posted 2 days ago
    Kendall,
    The only way that I have been able to add a list through a prompt is using INSTR as detailed in post #44 of this thread
    Bob
    --
    Bob Fogarty
    LionPATH - Reporting Team Lead
    The Pennsylvania State University



    Alliance 2026 Registration is Open!


  • 11.  RE: What's your favorite expression, case statement, trick?

    Posted 2 days ago

    Good morning Bob & Kendall,

    I wasn't able to locate Post #44 in my blizzard of emails, so I apologize if this is redundant.

    I use the following INSTR expression and criteria. As previously mentioned, this method is limited by the field width of PSQuery prompts, and by the character-count of whatever field you're using in the prompt. Prompt values are comma-space separated when entered, e.g. 

    XXXXX1, XXXXX2, XXXXX3, XXXXX4, etc.

    In this example, I'm prompting for EmplID. Univ. of Colorado uses 6-digit EmplIDs, and I think I can search five at a time. I don't use this option very often. My customers are usually FAs. But it does have its applications.

    (CASE

    WHEN REGEXP_INSTR(:1, A.EMPLID) > 0

    THEN A.EMPLID

    END)

    =

    A.EMPLID



    ------------------------------
    Scott Frey
    Senior Data Analyst - Human Resource Information 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.
    ------------------------------

    Alliance 2026 Registration is Open!


  • 12.  RE: What's your favorite expression, case statement, trick?

    Posted 2 days ago

    We have several collection queries that require multiple SID prompts, and so we have this configured for our use:

    First prompt is required but all others are marked optional:

    We pull SID lists from excel columns which adds the space, so in this case we use 25 SID list max.



    ------------------------------
    Elizabeth O'Connor
    System Operations Manager
    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.
    ------------------------------

    Alliance 2026 Registration is Open!


  • 13.  RE: What's your favorite expression, case statement, trick?

    Posted 2 days ago

    I think the posts may renumber themselves if one of us adds a reply to a "higher up" post.

    We've utilized this prompt method before, and agree that INSTR(:1, A.EMPLID) > 0 is the only way we've found to allow this.  Calling this a "limited number" is a bit unfair since a PS Text prompt can handle 4,000 characters (this is the PS universal limit for a Char vs CLOB)  So even if you're doing 'EMPLID1', 'EMPLID2',... you could get at least 266 IDs (assuming you use all 11 characters in EMPLID).

    @Scott Frey, I'm wondering why you use REGEXP_INSTR(...) rather than INSTR(...).  Is there an advantage to this?



    ------------------------------
    Scott Nishizaki
    Connected Campus Community of Practice
    Developer/Analyst
    Azusa Pacific University
    ------------------------------

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

    Alliance 2026 Registration is Open!


  • 14.  RE: What's your favorite expression, case statement, trick?

    Posted 2 days ago

    Thanks for providing the character limit for the prompts Scott. I'm always learning from you.

     

    To be honest, I don't know if there is an advantage to the REGEXP_

    I haven't used this expression in a few years.

    I just remembered having it in my "bag of dirty tricks and hacks" and thought I'd throw it out here in case anyone can benefit from it.

     

    ...it's probably something I learned at Alliance.

     

     

    Scott Frey

    Senior Data Analyst-HRIS, Employee Services

    University of Colorado

    1800 Grant Street, Suite 400

    Denver, CO  80203

    t  303 860 4200

    Scott.Frey@cu.edu
    www.cu.edu

    A black text on a white background  AI-generated content may be incorrect.

     




    Alliance 2026 Registration is Open!


  • 15.  RE: What's your favorite expression, case statement, trick?

    Posted 10 days ago

    I agree - this ANY solution makes much more sense than the 1 = 1 workaround.



    ------------------------------
    Kevin Shalla
    Director of Technology
    University of Chicago
    ------------------------------

    Alliance 2026 Registration is Open!


  • 16.  RE: What's your favorite expression, case statement, trick?

    Posted 10 days ago

    I actually use "Student Groups" to do this; I think it is much easier and doesn't limit the number of IDs I'm trying to get data on.  I have a couple of student groups to do this, but for in my area, I have:

    ARTP - A&R Temp Group

    I then make all students in ARTP inactivate from this student group and activate the IDs I need from an external file.  Then I write my query to find the data I need for these students.  In PUM 36, I can actually delete these out of the group, so that should make this process cleaner in the future.  



    ------------------------------
    Lee Raubolt
    Associate Director of Admissions and Records
    Truckee Meadows Community College
    ------------------------------

    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!


  • 17.  RE: What's your favorite expression, case statement, trick?

    Posted 10 days ago

    Oh, I like this solution a lot!

     




    Alliance 2026 Registration is Open!


  • 18.  RE: What's your favorite expression, case statement, trick?

    Posted 10 days ago

    I tend to do this with student groups too – if someone has a list of IDs in a file you can easily load them into a group and then query off that group.

    And being able to then delete the student group afterwards will make that a perfect solution

     

    Phil

     

     

     

    University of Derby

     

     

    Phil Sugden

     

    Head of Registry Systems Enhancement
    The Registry

    01332 591053
    p.sugden@derby.ac.uk

     

     

     

     




    Alliance 2026 Registration is Open!


  • 19.  RE: What's your favorite expression, case statement, trick?