Navigation

Showing posts with label SierraDNA. Show all posts
Showing posts with label SierraDNA. Show all posts

2/07/2015

SQL to get past checkouts from Innovative ILS

We have turned off the last patron to checkout an item field, but we wanted to track down the person who borrowed a laptop charger (missing a part).  This info is stored in CIRC_TRANS table, generally 14 days worth, to see all: 





SELECT
  transaction_gmt
FROM
  sierra_view.circ_trans
ORDER BY
  1
LIMIT
  100
;



To locate one item by barcode, use this code:


SELECT
  circ_trans.transaction_gmt,
  circ_trans.patron_record_id,
  circ_trans.item_record_id,
  circ_trans.due_date_gmt,
  item_view.barcode,
  item_view.itype_code_num,
  patron_record_fullname.first_name,
  patron_record_fullname.last_name
FROM
  sierra_view.circ_trans,
  sierra_view.item_view,
  sierra_view.patron_view,
  sierra_view.patron_record_fullname
WHERE
  item_view.id = circ_trans.item_record_id AND
  patron_view.id = circ_trans.patron_record_id AND
  patron_record_fullname.patron_record_id = patron_view.id AND
  item_view.barcode = '11111103690302'

ORDER BY
  circ_trans.due_date_gmt ASC;


Barcode is CHAR field, so can use ::text to set the number to text, double quotes do not work  (PGadmin client)


To get daily stats on checkouts:  (via Andrew Hollingsworth)



Select Distinct
  count(*),
  Case sierra_view.circ_trans.op_code When 'o' Then 'Checkout'
    When 'n' Then 'Hold' When 'nb' Then 'Title Hold' When 'ni' Then 'Item Hold'
    When 'f' Then 'Hold Fufilled' When 'i' Then 'Checkin'
    When 'r' Then 'Renewal' When 'h' Then 'Recall Hold'
    When 'u' Then 'Use Count' When 'b' Then 'Booking'
    When 'hb' Then 'Hold Recall Bib'
    When 'hi' Then 'Hold Recall Item'
    When 'hv' Then 'Hold Recall Volume' End As transtype From
  sierra_view.circ_trans
  Where
  sierra_view.circ_trans.transaction_gmt Between '02/10/2015 00:00:00'
  And '02/11/2015 24:00:00'
Group By
  sierra_view.circ_trans.op_code
Order by
transtype asc
 

10/31/2014

SierraDNA: SQL to get patrons who owe fines greater than $25

From Sierra Listserv, how to create query to get list of patrons who owe fines:



Hi Barbara:

David Jones is correct. You'll need to remove the check digit from your patron name to find a match in the database because the record number is stored internally without the check digit.

I have adapted an existing query of mine to get part way to what you are looking for. The query limits to patrons who owe $25 or more and who do not have manual block 'c'. I haven't limited to the age of the fines or fees. You'll have to fine tune it to get exactly what you're after. I included the check digit on the patron number thanks to some code provided a few months back by Jim Nicholls at University of Sydney.

The end result is 23 columns of data pertaining to the patron and the patron's outstanding fines and fees. Remove what you don't require. The data can be easily exported to Excel and then filtered to a specific patron.
-- ===================================================================================
-- Fines details for patrons Owing $25.00 or more
--  and without manual block 'c'
-- Brent Searle. Langara College. 2014-10-30
-- Check digit calculation via Jim Nicholls, University of Sydney
-- ===================================================================================
SELECT
  p.record_type_code||p.record_num||
  COALESCE( -- Check digit calculation
    CAST(
      NULLIF(
        (
          ( p.record_num % 10 ) * 2 +
          ( p.record_num / 10 % 10 ) * 3 +
          ( p.record_num / 100 % 10 ) * 4 +
          ( p.record_num / 1000 % 10 ) * 5 +
          ( p.record_num / 10000 % 10 ) * 6 +
          ( p.record_num / 100000 % 10 ) * 7 +
          ( p.record_num / 1000000 ) * 8
        ) % 11,
        10
      )
      AS CHAR(1)
    ),
    'x'
  )                                                  AS "Record Number",
  pnam.last_name||
  CASE
    WHEN pnam.first_name IS NOT NULL THEN ', '||pnam.first_name
    ELSE NULL
  END||
  CASE
    when pnam.middle_name IS NOT NULL THEN ' '||pnam.middle_name
    ELSE NULL
  END                                                AS "Patron Name",
  p.barcode                                          AS "Patron Barcode",
  p.home_library_code                                AS "Home Library",
  p.ptype_code                                       AS "Ptype code",
  ptnam.name                                         AS "Patron Type",
  f.invoice_num                                      AS "Invoice",
  CASE
    WHEN f.charge_code = '1' THEN 'MANUAL'
    WHEN f.charge_code = '2' THEN 'Overdue'
    WHEN f.charge_code = '3' THEN 'Replacement'
    WHEN f.charge_code = '4' THEN 'OverdueX'
    WHEN f.charge_code = '5' THEN 'Lost'
    WHEN f.charge_code = '6' THEN 'Overdue Renewal'
    WHEN f.charge_code = '7' THEN 'Rental'
    WHEN f.charge_code = '8' THEN 'RentalX'
    WHEN f.charge_code = '9' THEN 'Debit'
    WHEN f.charge_code = 'a' THEN 'Notice'
    WHEN f.charge_code = 'b' THEN 'Credit Card'
    WHEN f.charge_code = 'p' THEN 'Program Reg'
    ELSE 'unexpected code '||f.charge_code
  END                                                AS "Type",
  f.description                                      AS "Reason",
  f.title                                            AS "Title",
  i.barcode                                          AS "Item Barcode",
  f.charge_location_code                             AS "Item Location",
  to_char(f.assessed_gmt,'YYYY-MM-DD HH:MI AM')      AS "Date Assessed",
  to_char(f.checkout_gmt,'YYYY-MM-DD HH:MI AM')      AS "Date Checked Out",
  to_char(f.due_gmt,'YYYY-MM-DD HH:MIAM')            AS "Date Due",
  to_char(f.returned_gmt,'YYYY-MM-DD HH:MI AM')      AS "Date Returned",
  to_char(f.item_charge_amt,'$99G990D99')            AS "Item Charge",
  to_char(f.processing_fee_amt,'$99G990D99')         AS "Processing Fee",
  to_char(f.billing_fee_amt,'$99G990D99')            AS "Billing Fee",
  to_char(f.item_charge_amt+
  f.processing_fee_amt+
  f.billing_fee_amt,'$99G990D99')                    AS "Total",
  to_char(f.paid_amt,'$99G990D99')                   AS "Amount Paid",
  to_char(f.item_charge_amt+
  f.processing_fee_amt+
  f.billing_fee_amt-
  f.paid_amt,'$99G990D99')                           AS "Amount Due"
FROM
  sierra_view.patron_view                            AS p
JOIN -- join to patron full name
  sierra_view.patron_record_fullname                 AS pnam
  ON
  pnam.patron_record_id = p.id
JOIN -- join to ptype description
  sierra_view.ptype_property_myuser                  AS ptnam
  ON
  ptnam.value = p.ptype_code
JOIN -- join to fine data
  sierra_view.fine                                   AS f
  ON
  f.patron_record_id = p.id
JOIN -- join for item barcode
  sierra_view.item_view                              AS i
  ON
  i.id = f.item_record_metadata_id
WHERE
  p.owed_amt >= 25     -- patron owes $25.00 or more
  AND
  p.mblock_code != 'c' -- patron doesn't have manual block 'c'
ORDER BY
  2,14
;

--
Brent Searle
Library Systems Manager
Langara College
Vancouver BC

On 2014-10-30 2:23 PM, Leach, Barbara wrote:
I’m at the very beginning of trying to create a sql query to get a list of patrons who owe $25 or more in fines, they don’t have manual block ‘c’, their fine was assessed more than a month ago, and they don’t have a fee assessed more recently than a month ago.  I can use Create Lists to get the list, but the fields I want to export aren’t available for export.  So, I’m trying to re-create this with sql, so I can get the fields I want exported.

However, I can’t even get this simple query to return any data.  What am I doing wrong with this simple query?

SELECT
  patron_view.record_num AS "Record Number",
  patron_view.barcode AS "Barcode",
  patron_view.owed_amt AS "Amount Owed",
  patron_view.home_library_code AS "Home Library"
FROM
  sierra_view.patron_view
WHERE
  patron_view.record_num = '10068260';

When I run this, the output pane contains 0 rows.  I know that’s a valid patron record number, because it is a record that was included in my Create Lists results.

I need specific data about the fines, such as the date they were assessed, and that’s not available in Create Lists export fields.

If anyone already has a query that is similar to what I’m trying to create, would you mind sharing?

Thank you.
Barbara
Barbara Leach
Automated Services Coordinator

9/25/2014

SierraDNA: SQL to locate volume and item records

Using Innovative ILS and PostgrSQL ODBC data connection, want to locate items not attached to Volume records:  (from Sierra Listserv, Sept 25 2014)






I didn't realize that we could use this information too, not until I read your question.  But our volume statements for the volume records are just too widely ranging (TV shows, travel books, sets of movies) so I couldn't see how create lists could find this for us.  (The item-volume link is not an available search field for items.  It probably should be.)

So since we're all Sierra sites on this list, how about SQL?  I found 257 items on bib records with volume records, which aren't attached to a volume, in 31 sec. from among 1.2 million item record links.  The brir. and ir.record_ids  aren't useful to see, except for performing the search, as I'm really after just the Item Record Numbers.

Dan McMahon
MARINet, Novato CA
=====================================================
SELECT DISTINCT brir.item_record_id,
       ir.record_id,
       iv.record_num as "Item Record Number"
       FROM sierra_view.bib_record_item_record_link brir
      JOIN sierra_view.item_record ir on brir.item_record_id = ir.record_id
       JOIN sierra_view.item_view iv on ir.record_id = iv.id
       JOIN  sierra_view.bib_record_volume_record_link brvr on brir.bib_record_id = brvr.bib_record_id
       WHERE brvr.bib_record_id IS NOT NULL AND
       brir.item_record_id NOT IN

     (SELECT brir.item_record_id
       FROM  sierra_view.bib_record_item_record_link brir
       JOIN  sierra_view.bib_record_volume_record_link brvr on brir.bib_record_id = brvr.bib_record_id
       JOIN  sierra_view.volume_record_item_record_link vrir on brvr.volume_record_id = vrir.volume_record_id 
       WHERE vrir.item_record_id = brir.item_record_id
       )
ORDER BY 3 ASC

From: Scott, Sharon [mailto:sscott@ccpa.net]
Sent: Wednesday, September 10, 2014 11:02 AM
To: Sierra Users List
Subject: [sierra] Create Lists - Find items not attached to volumes

Does anyone know how to find items that are not attached to volumes for bib records that have volumes?  We have started separating multi-disc DVDs so that each disc circulates separately.  These are mostly TV series, e.g., NCIS. The complete first season.  We’ve put them into volumes to make it easy for patrons to place holds on only the ones they want.  Some of our libraries have not yet completed splitting their items and I need to find a list of those where the bib already has volumes set up, but a given item is not yet linked to the volume record.

Thanks,
Sharon


---------------------------------


My own folks wanted a revision to add the volume field info, and I stuck the bib number and title in there as well since that seems handy.

Dan McMahon
MARINet
===========================================

SELECT DISTINCT vv.record_num,
                vfv.field_content,
                bv.record_num,
                bv.title
    FROM sierra_view.volume_record vr
    JOIN sierra_view.volume_view vv on vr.record_id = vv.id
    JOIN  sierra_view.varfield_view vfv ON vr.record_id = vfv.record_id
    JOIN sierra_view.bib_record_volume_record_link brvr ON vr.record_id = brvr.volume_record_id
    JOIN sierra_view.bib_record br ON brvr.bib_record_id = br.id
    JOIN sierra_view.bib_view bv ON bv.id = br.record_id
   WHERE vfv.record_type_code   = 'j'
      AND vfv.varfield_type_code = 'v'
      AND vr.record_id NOT IN

    (SELECT vr.record_id FROM
            sierra_view.volume_record vr
            JOIN sierra_view.volume_record_item_record_link vrir on vrir.volume_record_id = vr.record_id
     )
=============================================