PS Query & SQL

Β View Only
Expand all | Collapse all

Need help in querying a query

  • 1.  Need help in querying a query

    Posted 03-07-2025 10:30 AM

    Okay, folks.  We are looking for queries that have criteria or having criteria looking for ACCOUNT_SF.ACCOUNT_BALANCE specifically looking for any logic that has 200 in it.  They need to change that to 500.

    So, I've come close, but I'm missing something.  This query has this logic:

    And it's not coming back in my query results.

    This is my query.  Can you guys help me fix it?  Please and thank you.

    SELECT DISTINCT A.qryname,
                    dbms_lob.Substr(Trim(expressiontext), 3, 1)
    FROM   psqrydefn A,
           psqryfield B,
           psqryexpr C
    WHERE  ( A.oprid = B.oprid
             AND A.qryname = B.qryname
             AND B.oprid = C.oprid
             AND B.qryname = C.qryname
             AND B.recname = 'ACCOUNT_SF'
             AND dbms_lob.Substr(Trim(expressiontext), 3, 1) LIKE '%200%'
             AND B.recname = 'ACCOUNT_SF'
             AND B.fieldname = 'ACCOUNT_BALANCE' ) 



    ------------------------------
    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: Need help in querying a query

    Posted 03-07-2025 10:40 AM

    Hi Dana –

     

    You are substringing to the first 3 characters of the expression.  That's the only part that is getting looked at.  Instead, change the substring line to this:

    AND dbms_lob.Substr(Trim(expressiontext), 2048, 1) LIKE '%200%'

     

    That's letting you search the first 2048 characters for your 200.

     

    Thanks!

     

    Vic

    ---

    Vic Goldberg

    Retiree, Temporary Employee

    University of Colorado Boulder

    Independent PeopleSoft FA Consultant

     

     




    Alliance 2026 Registration is Open!


  • 3.  RE: Need help in querying a query

    Posted 03-07-2025 10:47 AM

    I knew it was going to be something dumb.  I started with 3 and changed it to 500 but forgot to change it in the actual expression.  Rookie mistake!


    It's still not showing on my list.  I tried changing it to 2048 and it's still missing.

     

     




    Alliance 2026 Registration is Open!


  • 4.  RE: Need help in querying a query

    Posted 03-07-2025 11:01 AM

    Hi Dana,

    When using long text fields in criteria I usually do not use a SUBSTR to make sure I am searching all of the text, see below.  Depending on how many queries you are looking through and how your expressions are setup you might want to include the query field Select Number and Field Number in case it is in the experssion text in the fun PS query notation of like :%2.15.

    SELECT A.QRYNAME, TO_CHAR(SUBSTR(TRIM( C.EXPRESSIONTEXT),1,2048)), B.SELNUM, B.FLDNUM
      FROM PSQRYDEFN A, PSQRYFIELD B, PSQRYEXPR C
      WHERE ( A.OPRID = B.OPRID
         AND A.QRYNAME = B.QRYNAME
         AND A.OPRID = C.OPRID
         AND A.QRYNAME = C.QRYNAME
         AND B.RECNAME = 'ACCOUNT_SF'
         AND B.FIELDNAME = 'ACCOUNT_BALANCE'
         AND CASE WHEN  C.EXPRESSIONTEXT like '%200%' THEN 'Y' ELSE 'N' END = 'Y')



    ------------------------------
    Ross Nolan
    Data and Reporting Analysis
    University of California, Berkeley
    rvnolan@berkeley.edu
    ------------------------------

    Alliance 2026 Registration is Open!


  • 5.  RE: Need help in querying a query

    Posted 03-07-2025 11:24 AM

    Thanks, I changed it.  Still not bring back that one query.  So weird!

     




    Alliance 2026 Registration is Open!


  • 6.  RE: Need help in querying a query

    Posted 03-07-2025 11:26 AM

    I'm wondering if it is storing the data differently in the query because it is a between using numeric fields.  They may not be stored in the expressiontext field, but in one of the other query tables.

     

    Thanks!

     

    Vic

    ---

    Vic Goldberg

    Retiree, Temporary Employee

    University of Colorado Boulder

    Independent PeopleSoft FA Consultant

     

     




    Alliance 2026 Registration is Open!


  • 7.  RE: Need help in querying a query

    Posted 03-07-2025 11:33 AM

    It's literally driving me crazy.  Here is the missing query against the expression table.   What is going on?  It should be getting picked up and it's not.  ARRRRGGGG.

     

    I wouldn't think that field type is the issue, but maybe?

     

     




    Alliance 2026 Registration is Open!


  • 8.  RE: Need help in querying a query

    Posted 03-07-2025 11:50 AM

    Maybe add another WHEN to the case statement in the times that it is only a number?

    SELECT A.QRYNAME, TO_CHAR(SUBSTR(TRIM( C.EXPRESSIONTEXT),1,2048)), B.SELNUM, B.FLDNUM
      FROM PSQRYDEFN A, PSQRYFIELD B, PSQRYEXPR C
      WHERE ( A.OPRID = B.OPRID
         AND A.QRYNAME = B.QRYNAME
         AND A.OPRID = C.OPRID
         AND A.QRYNAME = C.QRYNAME
         AND B.RECNAME = 'ACCOUNT_SF'
         AND B.FIELDNAME = 'ACCOUNT_BALANCE'
         AND CASE WHEN  C.EXPRESSIONTEXT like '%200%' THEN 'Y'

    WHEN  TO_NUMBER(SUBSTR(C.EXPRESSIONTEXT,1,10)) = 200 THEN 'Y'

    ELSE 'N' END = 'Y')



    ------------------------------
    Ross Nolan
    Data and Reporting Analysis
    University of California, Berkeley
    rvnolan@berkeley.edu
    ------------------------------

    Alliance 2026 Registration is Open!


  • 9.  RE: Need help in querying a query

    Posted 03-07-2025 12:00 PM

    Last gasp.  In my query queries, I never use a trim.  I wonder if that could be the issue?

     

    Thanks!

     

    Vic

    ---

    Vic Goldberg

    Retiree, Temporary Employee

    University of Colorado Boulder

    Independent PeopleSoft FA Consultant

     

     




    Alliance 2026 Registration is Open!


  • 10.  RE: Need help in querying a query

    Posted 03-07-2025 12:57 PM

    I don't get it.  It's okay.  I think I'm giving up.  😊

     




    Alliance 2026 Registration is Open!


  • 11.  RE: Need help in querying a query

    Posted 03-07-2025 01:12 PM

    I ended up taking out the criteria for both ACCOUNT_SF and ACCOUNT_BALANCE and got a bunch of stuff I didn't want but the list wasn't too bad so I just deleted the extra stuff and now I'm getting that query.


    Thanks, All!

     




    Alliance 2026 Registration is Open!


  • 12.  RE: Need help in querying a query

    Posted 03-07-2025 03:03 PM
    Query has some convoluted-looking ways of storing the field, criteria and expression information.  Depending upon how the query builder "did things", the entries in the underlying tables could look quite different than what you might expect.  

    When you mentioned that you removed the record/field pair and got the query in your result, that leads me to believe something "different" was done in the query and you're in the "convoluted" situation.  Therefore, I would suggest the following to help "see" what's going on:

    • In query manager, compare the definition and usage of the field in a query which you did find with your selection to the one which you were not finding.  Are they different in some fashion?
    • Dump all the data for both of those queries from the tables PSQRYRECORD, PSQRYFIELD and PSQRYEXPR.  (PSQRYCRITERIA and PSQRYBIND can also be useful, although less likely in this situation.)  Anything look different?

    Perhaps you have done this - I did not notice any reference to these items in this discussion.




    David Ehrlich | Senior Business System Analyst - Admissions, Student Records, Data & Reporting

    Duke University | Student Information Services & System (SISS)

    david.ehrlich@duke.edu | 919-684-1270

    www.sissoffice.duke.edu





    Alliance 2026 Registration is Open!


  • 13.  RE: Need help in querying a query

    Posted 03-07-2025 03:17 PM

    I will next time.  I think we got a good list, and I've decided I'm done looking at it.  I need to practice my presentation one more time.  😊

     




    Alliance 2026 Registration is Open!


  • 14.  RE: Need help in querying a query

    Posted 03-08-2025 09:44 AM

    Try using:

    SELECT 
      A.qryname, 
      C.expressiontext 
    FROM 
      psqrydefn A, 
      psqryfield B, 
      psqryexpr C 
    WHERE 
      (
        A.oprid = B.oprid 
        AND A.qryname = B.qryname 
        AND B.oprid = C.oprid 
        AND B.qryname = C.qryname 
        AND B.recname = 'ACCOUNT_SF' 
        AND B.fieldname = 'ACCOUNT_BALANCE' 
        AND CASE WHEN Regexp_like(
          dbms_lob.Substr(C.expressiontext, 4000, 1), 
          '(^|[^0-9])200([^0-9]|$)', 
          'c'
        ) THEN 1 ELSE 0 END = 1
      )

    The expression is:

    CASE 
    WHEN REGEXP_LIKE(DBMS_LOB.SUBSTR(C.EXPRESSIONTEXT, 4000, 1), '(^|[^0-9])200([^0-9]|$)', 'c') THEN 1 
    ELSE 0 
    END



    ------------------------------
    Daniel Labrecque
    Senior 2 Business Systems Analyst/Functional Architect
    University of Nevada, Las Vegas
    ------------------------------

    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!


  • 15.  RE: Need help in querying a query

    Posted 03-09-2025 07:53 AM
    Thanks!  I'm going to try all suggestions and report back. 



    Alliance 2026 Registration is Open!


  • 16.  RE: Need help in querying a query

    Posted 03-19-2025 09:04 AM

    Okay, I've settled after returning from Alliance and wanted to come back to this issue and let you know what my problem was.

     

    David Ehrlich, you recommended looking at PSQRYRECORD, PSQRYFIELD and PSQRYEXPR for the query not being found and also one that is being found and I only needed to look as far as PSQRYRECORD.  The problem was I was hard coding the record to ACCOUNT_SF and this query was using

    ACCOUNT_TOT_VW instead.  Removing the record completely fixed my issue.

     

    Daron Wild, I also changed the expression to be the following and that also worked.  My original expression still worked, but I also like this one.

     

    Robert Fogarty your suggestion to change the expression to below also worked.

    AND DBMS_LOB.substr(EXPRESSIONTEXT,500) LIKE '200%'

     

    Dan Labrecque, I didn't get a chance to try yours.  I've never done that one before. Looks so confusing.  The easy stuff worked.  😊


    Thanks, everyone for your ideas.  This one was a rookie mistake.    Using a view instead of the actual record is what messed me up.

     




    Alliance 2026 Registration is Open!


  • 17.  RE: Need help in querying a query

    Posted 03-20-2025 01:56 PM

    Views tend to screw me up more often than not. One of my favorite records out there is PSSQLTEXTDEFN. If you know the name of the view (which you can generally find by Ctrl+J'ing the page and querying that page for its records and fields on PSPNLFIELD and PSDBFIELD), you can drop it into PSSQLTEXTDEFN as the SQLID and see exactly what's going on with it.



    ------------------------------
    Jesse Stumbris
    Associate Director
    University of Texas At Dallas
    ------------------------------

    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!


  • 18.  RE: Need help in querying a query

    Posted 03-09-2025 08:26 AM

    Dana,

    Verify that there is no "1," before "500"... this works for me then use your like 

    AND DBMS_LOB.substr(EXPRESSIONTEXT,500) LIKE '200%'



    ------------------------------
    Robert Fogarty PMP
    Reporting Team Lead | LionPATH Development and Maintenance Office
    The Pennsylvania State 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!


  • 19.  RE: Need help in querying a query

    Posted 03-08-2025 01:40 PM

    Your original SQL worked for me in SQL Developer, cannot see anything wrong with it. I changed a delivered PSQuery to a Between.

    Another variation to add to your list of examples, I've joined on field numbers  for the criteria.

    SELECT
        a.qryname,
        a.descr,
        b.recname,
        b.fieldname,
        c.expressiontext
       
    FROM
        psqrydefn     a,
        psqryfield    b,
        psqryexpr     c,
        psqrycriteria d
    WHERE
            b.recname = 'ACCOUNT_SF'
        AND b.fieldname = 'ACCOUNT_BALANCE'
        AND a.oprid = b.oprid
        AND a.qryname = b.qryname
        AND b.oprid = c.oprid
        AND b.qryname = c.qryname
        AND a.oprid = d.oprid
        AND a.qryname = d.qryname
        AND b.fldnum = d.lcrtfldnum
        AND dbms_lob.instr(expressiontext,'200') = 1



    ------------------------------
    Daron Wild
    Senior PeopleSoft Developer
    University of Cambridge
    ------------------------------

    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!


  • 20.  RE: Need help in querying a query

    Posted 03-09-2025 07:52 AM
    Thanks,  Daron!  I'm headed to Alliance, but I'll give this a shot and let you know if that query shows up.



    Alliance 2026 Registration is Open!