1

Re: Remove duplicate event recorders

Has anyone written a batch update to remove duplicate event recorders caused by merging events?

Charlie Barnes
Information Officer
Greater Lincolnshire Nature Partnership

2

Re: Remove duplicate event recorders

I have had a go at this. It works as a 'Quick' Batch Update from a Survey Event, but could be changed to work across the whole database, but some more testing would be needed before this was a good idea and an XML report which showed potential issues before the batch update was applied would be useful.  The main thing to watch with the process is the need to move the Recorders in the Sample_Recorder table, before deleting the event recorders. After running the Batch update both the Survey_Event and Sample Recorders should be checked. 

Mike 

 

<?xml version="1.0" ?>
<batchupdate menupath="LC Batch Updates" description="Deletes recorders from Survey_Event_Recorder where the recorder is duplicated within a survey event. Note that this takes into account teh Recorder role so if this is different the recorder will not be deleted. Changes the sample recorder to point to the lowest key and then removes the unwanted Survey_evenT_record record."
title="Deletes duplicated recorders on Events
">
<SQL>


<Where keytype="Event">

DECLARE @Hold char(16)
set @Hold = '%s'



CREATE TABLE #LCDelete (Name_Key char(16)  COLLATE SQL_Latin1_General_CP1_CI_AS,
        Survey_Event_key char(16)  COLLATE SQL_Latin1_General_CP1_CI_AS,
        Recorder_Role_key  char(16)  COLLATE SQL_Latin1_General_CP1_CI_AS,
        SE_Key_To_Use char(16)  COLLATE SQL_Latin1_General_CP1_CI_AS,
    Count_SE  int)           
       



INSERT INTO #LCDelete (Name_Key,Survey_Event_Key,Recorder_Role_Key,Count_SE) 
SELECT  Name_key, Survey_Event_key, Recorder_Role_key, Count(SE_Recorder_key)
FROM Survey_Event_recorder
GROUP BY Name_key, Survey_event_key, Recorder_Role_key
HAVING  Survey_Event_Key = @hold AND Count(SE_Recorder_key) &#62; 1


UPDATE #LCDELETE SET SE_Key_To_Use = (SELECT MIN(SE_Recorder_Key) FROM
Survey_Event_Recorder where Survey_Event_Recorder.Name_Key = #LCDELETE.Name_key AND
Survey_Event_Recorder.Survey_Event_Key  = #LCDELETE.Survey_event_key  AND
Survey_Event_Recorder.Recorder_Role_Key  = #LCDELETE.Recorder_Role_key)


UPDATE Sample_recorder SET SE_Recorder_Key = #LCDELETE.SE_Key_To_Use
FROM SAmple_recorder INNER JOIN Survey_event_recorder
ON Survey_event_recorder.SE_recorder_Key= Sample_recorder.SE_recorder_Key
INNER JOIN #LCDELETE ON
#LCDELETE.NAME_KEy = Survey_event_Recorder.name_key AND
#LCDELETE.SURVEY_EVENT_KEY = Survey_event_Recorder.SURVEY_EVENT_KEY AND
#LCDELETE.RECORDER_ROLE_KEy = Survey_event_Recorder.Recorder_role_key
WHERE  #LCDELETE.SE_Key_to_Use  &#60;&#62; Survey_event_Recorder.SE_Recorder_Key


DELETE FROM Survey_event_recorder
WHERE NOT EXISTS (SELECT * FROM SAMPLE_RECORDER WHERE sample_recorder.SE_Recorder_Key =
Survey_Event_recorder.SE_Recorder_Key) AND Survey_Event_recorder.Survey_event_key = @hold



DROP TABLE #LCDELETE








</Where>













</SQL>
</batchupdate>

Mike Weideli

3

Re: Remove duplicate event recorders

Thanks Mike, I'll give it a whirl

Charlie Barnes
Information Officer
Greater Lincolnshire Nature Partnership