I would definitely be interested in the SQL job! Many of our staff create record sets that are meant to be temporary but then end up being on the system for years. I’d love to start getting those cleaned up – thanks for sharing!
declare @rsids table ( rsid int )
insert into @rsids
select rs.RecordSetID
from Polaris.Polaris.RecordSets rs
where (coalesce(rs.ModificationDate, rs.CreationDate) < dateadd(month, -18, getdate()) and rs.name + coalesce(rs.Note, '') not like '%keep%' )
or (rs.CreatorID = 1 and rs.Name like 'Ebook Import%')
begin try
begin tran deleters
delete from Polaris.Polaris.BibRecordSets where RecordSetID in ( select * from @rsids )
delete from Polaris.Polaris.ItemRecordSets where RecordSetID in ( select * from @rsids )
delete from Polaris.Polaris.PatronRecordSets where RecordSetID in ( select * from @rsids )
delete from Polaris.Polaris.AuthorityRecordSets where RecordSetID in ( select * from @rsids )
delete from Polaris.Polaris.RecordSets where RecordSetID in ( select * from @rsids )
commit tran deleters
end try
begin catch
if (@@trancount > 0)
begin
rollback tran deleters
end
select ERROR_NUMBER() [ErrorNumber]
,ERROR_SEVERITY() [ErrorSeverity]
,ERROR_STATE() [ErrorState]
,ERROR_PROCEDURE() [ErrorProcedure]
,ERROR_LINE() [ErrorLine]
,ERROR_MESSAGE() [ErrorMessage]
end catch