Symptoms / Error |
|
Cause |
|
Fix |
*****build a table with duplicate counts and document name. This table will be joined by document name to the query that will change the status on all records with the same document name except the first one. SELECT PointerToSource as sourcepath, COUNT(*) as duplicates into duprecs FROM [DocuPhase].[dbo].[_obj_2] WHERE status != 'X' GROUP BY PointerToSource HAVING COUNT(*) > 1 ORDER BY duplicates DESC ****browse to show records that will be updated select pointertosource,objectid, status, duplicates, createdate,IDX_Vendor_ID,IDX_Invoice from [DocuPhase].[dbo].[_obj_2] join dbo.duprecs on Pointertosource=sourcepath where PointerToSource =sourcepath AND Status = 'E' AND ObjectID > (select MIN(ObjectID) from _obj_2 where PointerToSource = dbo.duprecs.sourcepath) order by duplicates desc, objectid ****Updates all the duplicate records excep the first one with a status of X so they wont show up begin tran update ap set status = 'X' from [docuphase].[dbo].[_obj_2] ap inner join dbo.duprecs on Pointertosource=sourcepath where PointerToSource =[dbo].[duprecs].sourcepath AND Status = 'E' AND ObjectID > (select MIN(ObjectID) from _obj_2 where PointerToSource = [dbo].[duprecs].sourcepath) rollback tran |
Summary |
|