Delimiter $$
/**
 * Author:  armen
 * Created: 21 juin 2018
 */
--  EntriesRefsData
Drop Procedure if Exists BUSINESS_COMPUTE_PUBLICVIEWS_ENTRIES_REFS_DATA $$
Create Procedure BUSINESS_COMPUTE_PUBLICVIEWS_ENTRIES_REFS_DATA ()
Begin
    Truncate Table TMP_V_PUBLIC_ENTRIES_REFS_DATA_VIEW;

    Insert Into TMP_V_PUBLIC_ENTRIES_REFS_DATA_VIEW (
        ENTRIES_ID_ENTRIES
        , ENTITIES_REF_DATAS_ID_ENTITIES_REF_DATAS
        , ENTITIES_REF_DATAS_CODE
        , ENTITIES_REF_ID_ENTITIES_REF
        , ENTITIES_REF_SEQUENCE
        , ENT_REF_TYPE_ID_ENT_REF_TYPES
        , ENTITIES_REF_TYPES_CODE
        , FULL_ENTRIES_REFS_SEQUENCE
    )
    Select 
        ENTRIES_ID_ENTRIES
        , ENTITIES_REF_DATAS_ID_ENTITIES_REF_DATAS
        , ENTITIES_REF_DATAS_CODE
        , ENTITIES_REF_ID_ENTITIES_REF
        , ENTITIES_REF_SEQUENCE
        , ENT_REF_TYPE_ID_ENT_REF_TYPES
        , ENTITIES_REF_TYPES_CODE
        , 
            (
                Case ENTITIES_REF_TYPES_CODE
--                     When 'ACCOUNTS' then 100
--                     When 'ACCRED_ACCOUNTS' then 200
--                     When 'ENTRIES' then 300
                    When 'ACCRED_ENTRIES' then 400
                    Else 300
                End
            )   + ENTITIES_REF_SEQUENCE
 
    From V_PUBLIC_ENTRIES_REFS_DATA_VIEW ;
End $$
Delimiter ;

