2/8/2019 - 6:28 AM

Unable to delete the specified item

declare @packageId uniqueidentifier
declare PackageRemoval cursor for

--**** Collect package Guids
select Guid
from vRM_Package_Item
where Name in (
       'Antivirus Inventory Package component'
       ,'Intel SCS - Software Package Resource'
       ,'Intel® SCS package'
       ,'OOB Site Server Configuration Package' 
       ,'OOB Site Server Inventory Package' 
       ,'OOB Site Service Agent - Software Package Resource' 
       ,'Out of Band Discovery Package' 
       ,'Out of Band Site Service Agent package' 
       ,'Out of Band Task Plug-in Package' 
       ,'Symantec Endpoint Protection Uninstall Management' 
or Name like '%Pluggable Protocols%' 


open PackageRemoval 
	fetch next from PackageRemoval into @packageId 
	while @@FETCH_STATUS = 0 
			update RM_ResourceSoftware_Package set Attributes = 0 where Guid = @packageId 
			update RM_ResourcePackage set Attributes = 0 where Guid = @packageId 
			delete from SWDPackageServer where PackageId = @packageId 
			delete from SWDPackageCodebase where PackageId = @packageId 
			delete from Evt_AeX_Package_Server_Package_Event where PackageId = @packageId 
			delete from Evt_NS_Scheduled_Event where ItemGuid = @packageId 
			delete from ItemSchedule where ItemGuid = @packageId -- Uncomment if the package is broken. 
			insert into ItemToDelete  
			select @packageId, GETDATE () 
			fetch next from PackageRemoval into @packageId 
close PackageRemoval 
deallocate PackageRemoval