org_unit_id ALIAS for $2;
lms_bib_id BIGINT;
library_code TEXT;
+ last_circ_lib TEXT;
bar_code TEXT;
last_use_date TEXT;
cumulative_use_total TEXT;
END IF;
SELECT REPLACE(NOW()::DATE::TEXT, '-', '') INTO extract_date;
SELECT ou.shortname INTO library_code FROM actor.org_unit ou, asset.copy c WHERE ou.id = c.circ_lib AND c.id = item;
+ SELECT aou.shortname, REPLACE(circ.xact_start::DATE::TEXT, '-', '') INTO last_circ_lib, last_use_date FROM actor.org_unit aou INNER JOIN action.circulation circ ON (circ.circ_lib = aou.id)
+ WHERE circ.target_copy = item ORDER BY circ.xact_start DESC LIMIT 1;
SELECT REPLACE(xact_start::DATE::TEXT, '-', '') INTO last_use_date FROM action.circulation WHERE target_copy = item ORDER BY xact_start DESC LIMIT 1;
SELECT circ_count INTO cumulative_use_total FROM extend_reporter.full_circ_count WHERE id = item;
IF cumulative_use_total IS NULL THEN
|| lms_bib_id || ','
|| COALESCE(collectionHQ.quote(authority_code), '') || ','
|| COALESCE(collectionHQ.quote(library_code), '') || ','
+ || COALESCE(collectionHQ.quote(last_circ_lib), '') || ','
|| COALESCE(collectionHQ.quote(bar_code), '') || ','
|| COALESCE(collectionHQ.quote(last_use_date), '') || ','
|| COALESCE(cumulative_use_total, '') || ','