Courtesy of our developer @mfields. Deletes ALL unlinked authorities if the authority record is older than 30 days. Requires write permission on SQL database.
!!!THIS COULD BREAK YOUR ENTIRE POLARIS DATABASE. INNOVATIVE WILL CHARGE YOU TO HELP FIX IT. USE AT YOUR OWN RISK!!!
declare @logonBranchId int = -- input branch ID number
declare @logonUerId int = -- input staff member user ID number
declare @logonWorkstationId int = '0000' --input workstation ID number
declare valueCursor cursor for
select ar.RecordID
from polaris.polaris.ViewAuthorityRecords ar
join polaris.polaris.AuthorityRecords ar2
on ar2.AuthorityRecordID = ar.RecordID
where ar.LinkedBibCount = 0
and ar.LinkedSeeAlsoCount = 0
and ar.Name = 'y'
and ar.Subject = 'y'
and ar2.ModificationDate < dateadd(day, -30, getdate())
declare @currentAuthority int = 0
declare @recordDeleted bit = 0
declare @markedForDeletion bit = 0
open valueCursor
fetch next from valueCursor into @currentAuthority
while @@FETCH_STATUS = 0
begin
exec Polaris.Polaris.Cat_DeleteAuthorityRecordProcessing @currentAuthority, @logonBranchId, @logonUerId, @logonWorkstationId, 0, @recordDeleted out, @markedForDeletion out
fetch next from valueCursor into @currentAuthority
end
close valueCursor
deallocate valueCursor