1

Topic: Importing old habitat data

I'm trying to import some old records extracted from a R2002 database which include related biotope occurrences. Some of the biotope codes are valid but not current (i.e. from an old version of the classification) - e.g. K- Marine, which was on version 1 of the Phase 1 Habitat Classification. So the habitats are in the biotope table (Biotope key NBNSYS0000001173 for Marine) but the import routine won't let me import it as it's no longer in a current version of the relevant biotope dictionary. Any suggestions of how I import these? I could ignore them and enter them by hand but I similarly can't seem to input these old habitat types either.

Any suggestions?

MARK

Mark Pollitt
SWSEIC (formerly DGERC)

2

Re: Importing old habitat data

Hi

I think some posts have gone missing in this topic, because the NBN have moved the Forum to a new server.

Mike

Mike Weideli

3

Re: Importing old habitat data

Indeed they have Mike

Mark Pollitt
SWSEIC (formerly DGERC)

4

Re: Importing old habitat data

Assumimg you want to use the key this will do it

Biotope List Item Key needs to be in the biotope column. When matching select the Phase 1 habitat classification. If it works it is a change which could be made  in R6. Could be useful in the future to someone.
 

USE [NBNData]
GO
/****** Object:  StoredProcedure [dbo].[usp_IWMatch_Biotopes]    Script Date: 12/19/2016 16:29:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*===========================================================================*\
  Description:    Populate import table with matched values for unique matched only.

  Parameters:    @ChecklistKey

  Created:    June 2004

  Last revision information:
    $Revision: 1 $
    $Date: 30/07/04 15:03 $
    $Author: Johnvanbreda $

\*===========================================================================*/
ALTER PROCEDURE [dbo].[usp_IWMatch_Biotopes]
    @ChecklistKey char(16)
AS
   UPDATE    #Biotopes
        SET    Match_Key = BLI.Biotope_List_Item_Key,
            Match_Value =  BLI.Biotope_List_Item_Key,
            Classification = BC.Short_Name,
            Classification_Key = @ChecklistKey,
            Match_Count = 1
        FROM   
           BIOTOPE_LIST_ITEM BLI
           INNER JOIN BIOTOPE_CLASSIFICATION_VERSION BCV
           ON BCV.BT_CL_VERSION_KEY = BLI.BT_CL_VERSION_KEY
           INNER JOIN BIOTOPE_CLASSIFICATION BC
           ON BC.BIOTOPE_CLASSIFICATION_KEY=BCV.BIOTOPE_CLASSIFICATION_KEY
       
        WHERE    #Biotopes.Import_Value  = BLI.Biotope_List_Item_Key
 
   
    -- Set Match_Count first.
    UPDATE    #Biotopes
    SET    Match_Count =  (SELECT Count(*)
                FROM Biotope B
                JOIN Biotope_List_Item BLI ON BLI.Biotope_Key = B.Biotope_Key
                JOIN Biotope_Classification_Version BCV ON BCV.BT_CL_Version_Key = BLI.BT_CL_Version_Key
                WHERE    (BLI.BT_CL_Version_To IS NULL
                         OR Import_Value = BLI.BIOTOPE_LIST_ITEM_KEY)
                AND     BCV.Biotope_Classification_Key = @ChecklistKey
                AND    (Import_Value = B.Short_Term
                OR     Import_Value = B.Full_Term
                OR     Import_Value = B.Original_Code
                OR     Import_Value = B.Original_Code + ', ' + B.Short_Term
                OR     Import_Value = B.Original_Code + '-' + B.Short_Term
                OR     Import_Value = B.Original_Code + '_' + B.Short_Term)
                )
    WHERE    Match_Key IS NULL

    -- Now get values and keys for unique matches only.
    UPDATE    #Biotopes
    SET    Match_Key = Biotope_List_Item_Key,
        Match_Value = dbo.ufn_GetFormattedBiotopeName(Biotope_List_Item_Key),
        Classification = BC.Short_Name,
        Classification_Key = BC.Biotope_Classification_Key
    FROM    Biotope B
    JOIN    Biotope_List_Item BLI ON B.Biotope_Key = BLI.Biotope_Key
    JOIN    Biotope_Classification_Version BCV ON BCV.BT_CL_Version_Key = BLI.BT_CL_Version_Key
    JOIN    Biotope_Classification BC ON BC.Biotope_Classification_Key = BCV.Biotope_Classification_Key
    WHERE    Match_Count = 1
    AND    Match_Key IS NULL
    AND    (BLI.BT_CL_Version_To IS NULL OR Import_Value = BLI.BIOTOPE_LIST_ITEM_KEY)
    AND    BC.Biotope_Classification_Key = @ChecklistKey
    AND     (Import_Value = B.Short_Term
    OR     Import_Value = B.Full_Term
    OR     Import_Value = B.Original_Code
    OR     Import_Value = B.Original_Code + ', ' + B.Short_Term
    OR     Import_Value = B.Original_Code + '-' + B.Short_Term
    OR     Import_Value = B.Original_Code + '_' + B.Short_Term)

Mike Weideli

5

Re: Importing old habitat data

Thanks Mike

Will try that later today and report back.

MARK

Mark Pollitt
SWSEIC (formerly DGERC)

6

Re: Importing old habitat data

Hi Mike

A test on a small number of records worked successfully and brings in the 'old' Phase 1 habitat codes fine. As you suggest it's possible that this might be useful to others in future too.

Thanks for your help

MARK

Mark Pollitt
SWSEIC (formerly DGERC)