1 (edited by RobLarge 07-12-2010 16:49:42)

Re: Batch Update question

I guess this is probably a question for Mike, but if anyone else can answer it please feel free.

I am trying to create a batch update, which will only be run from the Tools menu (not as a quick report), which will set the confidential flag for all occurrences of all taxa which have been given our local Taxon Designation "Confidential" (a designation we have assigned to all taxa which we regard as confidential under all circumstances).

I have the SQL necessary to do the update (almost), but am unsure about how to wrap it up as a batch update (has any help been written for this yet?)

The SQL is as follows

UPDATE     TAXON_OCCURRENCE AS TOCC INNER JOIN
                          TAXON_DETERMINATION AS TDET ON
                        TOCC.TAXON_OCCURRENCE_KEY = TDET.TAXON_OCCURRENCE_KEY
                        INNER JOIN
                          TAXON_DESIGNATION AS TDES INNER JOIN
                          INDEX_TAXON_NAME AS ITN ON
                        TDES.TAXON_LIST_ITEM_KEY = ITN.TAXON_LIST_ITEM_KEY INNER JOIN
                          INDEX_TAXON_NAME AS ITN1 ON
                        ITN.RECOMMENDED_TAXON_LIST_ITEM_KEY =
                        ITN1.RECOMMENDED_TAXON_LIST_ITEM_KEY ON
                          TDET.TAXON_LIST_ITEM_KEY = ITN1.TAXON_LIST_ITEM_KEY
SET         TOCC.CONFIDENTIAL = 1
                TOCC.CHANGED_BY = (SELECT NAME_KEY FROM NAME WHERE
                              <Condition field="Name.Name_Key" type="CurrentUserID"
                                 name="Current User ID"     operator="equal" /> )
                TOCC.CHANGED_DATE = GETDATE()
WHERE         (TDES.TAXON_DESIGNATION_TYPE_KEY = 'DSS0062800000003')

I think the SQL is correct, but how do I make this into a batch update?

Thanks in anticipation

Rob Large
Wildlife Sites Officer
Wiltshire & Swindon Biological Records Centre

2 (edited by MikeWeideli 07-12-2010 21:06:16)

Re: Batch Update question

Rob

The following (down to the ************)  is your sql in a batch update format. You need to paste this into notepad and save it with an xml extension in the batch update folder. The title, path and description need to be edited to what you need. I think though there may be problems with your sql as it will not run. I am not sure if all the joins are complete and it looks like the set satement is missing some commas.  I haven't attempted a fix of your sql as the format you have used for the update  is not  one I am familiar with so I have attempted my own version which is below the ************. Hope this helps.   

Mike
 
<?xml version="1.0" ?>
<batchupdate menupath="My Path" description=""
title="My Title"
>
<SQL>

<Where keytype="Default">

UPDATE     TAXON_OCCURRENCE AS TOCC INNER JOIN
                          TAXON_DETERMINATION AS TDET ON
                        TOCC.TAXON_OCCURRENCE_KEY = TDET.TAXON_OCCURRENCE_KEY
                        INNER JOIN
                          TAXON_DESIGNATION AS TDES INNER JOIN
                          INDEX_TAXON_NAME AS ITN ON
                        TDES.TAXON_LIST_ITEM_KEY = ITN.TAXON_LIST_ITEM_KEY INNER JOIN
                          INDEX_TAXON_NAME AS ITN1 ON
                        ITN.RECOMMENDED_TAXON_LIST_ITEM_KEY =
                        ITN1.RECOMMENDED_TAXON_LIST_ITEM_KEY ON
                          TDET.TAXON_LIST_ITEM_KEY = ITN1.TAXON_LIST_ITEM_KEY
SET         TOCC.CONFIDENTIAL = 1
                TOCC.CHANGED_BY = (SELECT NAME_KEY FROM NAME WHERE
                              <Condition field="Name.Name_Key" type="CurrentUserID"
                                 name="Current User ID"     operator="equal" /> )
                TOCC.CHANGED_DATE = GETDATE()
WHERE         (TDES.TAXON_DESIGNATION_TYPE_KEY = 'DSS0062800000003')


</Where>

</SQL>
</batchupdate>

*************** MY VERSION

<?xml version="1.0" ?>
<batchupdate menupath="My Path" description=""
title="My Title"
>
<SQL>

<Where keytype="Default">

UPDATE     TAXON_OCCURRENCE
SET     CONFIDENTIAL = 1,
    CHANGED_BY = (SELECT NAME_KEY FROM NAME WHERE
                  <Condition field="Name.Name_Key" type="CurrentUserID"
                             name="Current User ID"     operator="equal" /> ),
     CHANGED_DATE = GETDATE()

FROM
        TAXON_OCCURRENCE TOCC INNER JOIN
                          TAXON_DETERMINATION TDET
                        ON TOCC.TAXON_OCCURRENCE_KEY = TDET.TAXON_OCCURRENCE_KEY AND TDET.PREFERRED = 1
                        INNER JOIN
                        INDEX_TAXON_NAME ITN1
                        ON TDET.TAXON_LIST_ITEM_KEY = ITN1.TAXON_LIST_ITEM_KEY
                          INNER JOIN
            INDEX_TAXON_NAME ITN
                        ON ITN.RECOMMENDED_TAXON_LIST_ITEM_KEY = ITN1.RECOMMENDED_TAXON_LIST_ITEM_KEY
            INNER JOIN
            TAXON_DESIGNATION TDES
                        ON TDES.TAXON_LIST_ITEM_KEY = ITN.TAXON_LIST_ITEM_KEY
                                         
WHERE         TDES.TAXON_DESIGNATION_TYPE_KEY = 'DSS0062800000003'


</Where>

Mike Weideli

3

Re: Batch Update question

Thanks Mike

I had tested the sql in Management Studio, before making a few minor changes and it seemed to work, but the final changes were made late in the day so its entirely possible I messed it up.

Thanks anyway.

Rob Large
Wildlife Sites Officer
Wiltshire & Swindon Biological Records Centre

4

Re: Batch Update question

This looks to be a great method for automatically setting the confidential flag for a long list of sensitive species.  However, am I correct in thinking that the local taxon designations would be overwritten by a dictionary update?

Mike Beard
Natural Course Project Officer
Greater Manchester Local Records Centre

5

Re: Batch Update question

User created taxon designations should persist (at least ours do!)

I think this thread should help: http://forums.nbn.org.uk/viewtopic.php?id=1055

Charlie Barnes
Information Officer
Greater Lincolnshire Nature Partnership

6

Re: Batch Update question

Thanks Charlie.  That is a great thread, maybe it was too many pages down when I was searching.

Mike Beard
Natural Course Project Officer
Greater Manchester Local Records Centre