Skip to main content
ExLibris

Knowledge Assistant

BETA
 
  • Subscribe by RSS
  • Back
    Aleph

     

    Ex Libris Knowledge Center
    1. Search site
      Go back to previous article
      1. Sign in
        • Sign in
        • Forgot password
    1. Home
    2. Aleph
    3. Knowledge Articles
    4. Adding patron name to patron-owes SQL

    Adding patron name to patron-owes SQL

    1. Last updated
    2. Save as PDF
    3. Share
      1. Share
      2. Tweet
      3. Share
    No headers
    • Article Type: General
    • Product: Aleph
    • Product Version: 20

    Description:
    We would like to add z303 name to the following sql. I think this takes a multiple join including z31, z308 and z303, but I can't figure out how to do it.

    set echo off
    set pause off
    set term off
    set show off
    set feed off
    set verify off
    set pagesize 58

    column PATRON_ID format a14 heading "Patron-ID"
    column BALANCE format $999,999.99 heading "Balance"

    spool patron-balance-all.lst
    select substr(z31_rec_key,1,12) PATRON_ID, sum(to_number(concat(translate(z31_credit_debit,'CD','-0'),translate(z31_sum/100,'
    ','0')))) BALANCE
    from z31
    where z31_status = 'O'
    group by substr(Z31_REC_KEY,1,12) HAVING sum(to_number(concat(translate(z31_credit_debit,'CD','-0'),translate(z31_sum/100,'
    ','0')))) > 0
    order by BALANCE desc;

    spool off
    exit;

    Resolution:
    [From site:] We got this working. There were two issues:

    First, the formatting of the query was in part causing Oracle to think it reached the end of the statement before it had fully been parsed.

    Second, even with the statement formatting corrected the statement was running into ORA-00979 “not a GROUP BY expression error. That error is caused because GROUP BY clauses MUST contain each and every element of the SELECT statement used.

    Corrected SQL:

    set echo off
    set pause off
    set term off
    set show off
    set feed off
    set verify off
    set pagesize 58

    column PATRON_ID format a14 heading "Patron-ID"
    column BALANCE format $999,999.99 heading "Balance"
    column NAME format a30 heading "NAME"

    spool patron-balance-all-CES.lst
    select z303_name NAME, substr(z31_rec_key,1,12) PATRON_ID,
    sum(to_number(concat(translate(z31_credit_debit,'CD','-0'),translate(z31_sum/100,'
    ','0')))) BALANCE
    from z31, z303
    where z31_status = 'O'
    and
    substr(z31_rec_key,1,12) = z303_rec_key
    group by
    z303_name,
    substr(z31_rec_key,1,12) HAVING
    sum(to_number(concat(translate(z31_credit_debit,'CD','-0'),translate(z31_sum/100,'
    ','0')))) > 0
    order by BALANCE desc;

    spool off
    exit;


    • Article last edited: 10/8/2013
    View article in the Exlibris Knowledge Center
    1. Back to top
      • Adding Order Status Date (Z68-ORDER_STATUS_DATE_X) to Order Index
      • Adding periods to name headings
    • Was this article helpful?

    Recommended articles

    1. Article type
      Topic
      Language
      English
      Product
      Aleph
    2. Tags
      1. 20
      2. contype:kba
      3. Prod:Aleph
      4. Type:General
    1. © Copyright 2025 Ex Libris Knowledge Center
    2. Powered by CXone Expert ®
    • Term of Use
    • Privacy Policy
    • Contact Us
    2025 Ex Libris. All rights reserved