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. SQL retrieves all items for an ADM record, rather than just a specific item

    SQL retrieves all items for an ADM record, rather than just a specific item

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

    Problem Symptoms:
    An SQL query which should retrieve just a specific item or items for a particular ADM record retrieves all items for the ADM record. See example in Additional Information.

    Cause:
    The item is being JOIN'ed based on just the first 9 digits (the ADM#) of the z30_rec_key:

    JOIN HPL50.z30 ON substr(z31_key,1,9) = substr(z30_rec_key,1,9)

    This means that all items for this ADM record will be included.

    Resolution:
    Include the entire 15-digit item key in the JOIN:

    JOIN HPL50.z30 ON substr(z31_key,1,15) = substr(z30_rec_key,1,15)

    Additional Information

    Example:

    SELECT "Patron Status",
    "Patron Barcode",
    "Name",
    "Title",
    "Barcode",
    ( D - C ) / 100 "Amount Owed"
    FROM (
    SELECT ( SELECT Z305_BOR_STATUS
    FROM HPL50.Z305
    WHERE Z305_REC_KEY = Z303_REC_KEY || 'HPL '
    ) "Patron Status",
    ( SELECT substr( Z308_REC_KEY, 3 )
    FROM SYS00.Z308
    WHERE Z308_ID = Z303_REC_KEY
    AND substr( Z308_REC_KEY, 1, 2 ) = '01'
    AND Z308_STATUS = 'AC'
    ) "Patron Barcode",
    Z303_NAME "Name",
    z13_title "Title",
    z30_barcode "Barcode",
    nvl( sum( decode( Z31_CREDIT_DEBIT, 'C', Z31_SUM ) ), 0 ) "C",
    nvl( sum( decode( Z31_CREDIT_DEBIT, 'D', Z31_SUM ) ), 0 ) "D"
    FROM HPL50.Z31
    INNER JOIN SYS00.Z303 ON substr( Z31_REC_KEY, 1, 12 ) = Z303_REC_KEY
    JOIN HPL50.z30 ON substr(z31_key,1,15) = substr(z30_rec_key,1,15)
    JOIN SYS01.Z13 ON substr(z31_key,1,9) = Z13_REC_KEY
    WHERE Z31_STATUS = 'O'
    AND Z31_SUB_LIBRARY LIKE 'HPL '
    and z303_name like 'ECHEVERRIA, ELIZ%'
    GROUP BY Z303_REC_KEY,
    Z303_NAME_KEY,
    Z303_NAME,
    Z31_KEY,
    z13_title,
    z30_barcode
    ORDER BY 1, Z303_NAME_KEY, 5
    )
    WHERE ( D - C ) > 00000;

    Category: Circulation (500)


    • Article last edited: 12/11/2014
    View article in the Exlibris Knowledge Center
    1. Back to top
      • SQL Report of items which have never been checked out
      • SQL scripts fail or run slow after optimizer changes
    • Was this article helpful?

    Recommended articles

    1. Article type
      Topic
      Language
      English
      Product
      Aleph
    2. Tags
      1. 20
      2. Circulation (500)
      3. contype:kba
      4. Prod:Aleph
      5. 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