Navigation

5/26/2014

SQL to get list of patrons who have records checked out


From Sierra listserv, Pam Childers

SELECT
  p.record_num          AS "patron_record",
  max(n.last_name)      AS "last_name",
  max(n.first_name)     AS "first_name",
  p.checkout_count           AS "checkout_count",
  substring(p.barcode,7,7)             AS "iwu_id",
  s.content             AS "email_address"
FROM sierra_view.patron_view p
 JOIN sierra_view.patron_record_fullname n
     ON n.patron_record_id = p.id
 JOIN sierra_view.subfield_view s         
    ON s.record_num = p.record_num
WHERE
  p.ptype_code = 0
  AND s.field_type_code = 'z'
  AND s.record_type_code = 'p'
  AND p.expiration_date_gmt > current_date
  AND p.checkout_count > 0
GROUP BY p.record_num, last_name, first_name, p.barcode, s.content, p.checkout_count ORDER BY last_name, first_name

No comments:

Post a Comment