- Article Type: General
- Product: Aleph
- Product Version: 20
I have a library requesting a report of patrons to whom the LIBRARY owes money. Since I am not finding any canned reports (am I overlooking something?), I am trying an SQL query but am having difficulties finding the correct z field. Can you help with a query that would provide that information to my user?
I did not find any standard report that does what you want to do, so I think SQL is the ticket. The information you want is mostly in the Z31 table, in the Z31_SUM field. This field can be either a credit or a debit, depending on the value of Z31_CREDIT_DEBIT. I think what you need to do is to sum up the amounts for each patron and determine if they are positive (they owe us) or negative (we owe them). If the sum is negative, we can then go out and get more information about the specific amounts.
I found some SQL that was offered by Christine Moulen from MIT for transferring charges to the Bursar, and I made some changes to make it closer to what you need. You will need to change the various libraries to match your setup, and may need to tweak some other parts, I don't know. I haven't analyzed each field and test in the SQL below to know if it might cause problems. In any case, I hope this will get you on your way.
WHERE RTRIM(Z303_REC_KEY) = Z308_ID
AND RTRIM(Z303_REC_KEY) = RTRIM(SUBSTR(Z305_REC_KEY,1,12))
AND SUBSTR(Z305_REC_KEY,13,5) = 'ALEPH'
AND SUBSTR(Z308_REC_KEY,1,2) = '02'
AND Z308_STATUS = 'AC'
AND SUBSTR(Z31_REC_KEY,1,12) = Z303_REC_KEY
AND Z31_STATUS = 'O'
AND Z30_REC_KEY = SUBSTR(Z31_KEY,1,15)
AND SUBSTR(Z103.Z103_REC_KEY_1,1,5) = 'USM01'
AND SUBSTR(Z103.Z103_REC_KEY,6,9) = SUBSTR(Z30_REC_KEY,1,9)
AND SUBSTR(Z103.Z103_REC_KEY_1,6,9) = Z13.Z13_REC_KEY
AND Z305_BOR_STATUS <> '08'
AND SUBSTR(Z31_REC_KEY,1,12) IN
WHERE Z31_STATUS = 'O'
))) < 0
The following is a similar, somewhat simpler query from Fang Peng at SUNY Stony Brook:
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"
select substr(z31_rec_key,1,12) PATRON_ID,
where z31_status = 'O'
group by substr(Z31_REC_KEY,1,12) HAVING
','0')))) < 1
order by BALANCE desc;
<end Fang Peng query>
- Article last edited: 10/8/2013