Delimiter //
/**
 * Updates the FI_ANA_MEMBERS table from FI_ANA
 *
 * Attention, au préalable appeler la procédure :
 *	- BUSINESS_FI_ANA_INSERT_NEW_MEMBERS
 *
 * @author Benoit
 * @see BUSINESS_UPDATE_FIANA
 * @see BUSINESS_FI_ANA_INSERT_NEW_MEMBERS
 * @see BUSINESS_BACKUP_FIANA_MEMBERS
 * @see BUSINESS_BACKUP_FIANA_MEMBERS_FROM_HISTO
 */ 
Drop Procedure if Exists BUSINESS_UPDATE_FIANA_MEMBERS//
 
Create Procedure BUSINESS_UPDATE_FIANA_MEMBERS(In idmembers Int Unsigned)
Begin

--     Declare memberFilter Varchar(10) Default Ifnull(idmembers, '%');
    Set @bufm_idmembers  = idmembers;
    Set @bufm_idmembers_min  = Coalesce(@bufm_idmembers, 0);
    Set @bufm_idmembers_max  = Coalesce(@bufm_idmembers, 10000000);

    update_fiana_members: Begin

            Drop Temporary Table If Exists TMP_FIANA_MBRS_UPDATE;
            Create Temporary Table TMP_FIANA_MBRS_UPDATE  (
                    MEMBERS_ID_MEMBERS Int Unsigned not Null
                    , FI_ANA_ACCOUNTS_COUNT Int
                    , FI_ANA_ACCOUNTS_HASH Varchar(33)
                    , FI_ANA_OUTSTANDING Decimal(19, 4)
                    , FI_ANA_OVERDUE Decimal(19, 4)
                    , FI_ANA_NOT_OVERDUE Decimal(19, 4)
                    , FI_ANA_DUE Decimal(19, 4)
                    , FI_ANA_FROZEN_AMOUNT Decimal(19, 4)
                    , FI_ANA_BLOCKED_ALL Decimal(19, 4)
                    , FI_ANA_BLOCKED_NOTOVERDUE Decimal(19, 4)
                    , FI_ANA_AGE_PORTFOLIO_PERIOD1 Decimal(19, 4)
                    , FI_ANA_AGE_PORTFOLIO_PERIOD2 Decimal(19, 4)
                    , FI_ANA_AGE_PORTFOLIO_PERIOD3 Decimal(19, 4)
                    , FI_ANA_AGE_PORTFOLIO_PERIOD4 Decimal(19, 4)
                    , FI_ANA_AGE_PORTFOLIO_PERIOD5 Decimal(19, 4)
                    , FI_ANA_AGE_PORTFOLIO_PERIOD6 Decimal(19, 4)
                    , FI_ANA_AGE_PORTFOLIO_PERIOD7 Decimal(19, 4)
                    , FI_ANA_AGE_PORTFOLIO_PERIOD8 Decimal(19, 4)
                    , FI_ANA_AGE_ACCOUNT_PERIOD1 Decimal(19, 4)
                    , FI_ANA_AGE_ACCOUNT_PERIOD2 Decimal(19, 4)
                    , FI_ANA_AGE_ACCOUNT_PERIOD3 Decimal(19, 4)
                    , FI_ANA_AGE_ACCOUNT_PERIOD4 Decimal(19, 4) 
                    , FI_ANA_CURRENT_ORDER_AMOUNT Decimal(19, 4)
                    , FI_ANA_BLOCKED_ORDER_AMOUNT Decimal(19, 4)
                    , FI_ANA_DELIVERY_TOBEINVOICED Decimal(19, 4)
                    , FI_ANA_BLOCKED_DELIVERY_TOBEINVOICED Decimal(19, 4)
                    , FI_ANA_BANK_DRAFT Decimal(19, 4)
                    , FI_ANA_SALES Decimal(19, 4)
                    , FI_ANA_PAYMENT Decimal(19, 4)
                    , FI_ANA_UNBOUND_OUTSTANDING Decimal(19, 4)
                    , FI_ANA_UNBOUND_OVERDUE Decimal(19, 4)
                    , FI_ANA_UNBOUND_NOT_OVERDUE Decimal(19, 4)
                    , FI_ANA_UNBOUND_DUE Decimal(19, 4)
                    , FI_ANA_UNBOUND_FROZEN_AMOUNT Decimal(19, 4)
                    , FI_ANA_UNBOUND_BLOCKED_ALL Decimal(19, 4)
                    , FI_ANA_UNBOUND_BLOCKED_NOTOVERDUE Decimal(19, 4)
                    , FI_ANA_UNBOUND_CURRENT_ORDER_AMOUNT Decimal(19, 4)
                    , FI_ANA_UNBOUND_BLOCKED_ORDER_AMOUNT Decimal(19, 4)
                    , FI_ANA_UNBOUND_DELIVERY_TOBEINVOICED Decimal(19, 4)
                    , FI_ANA_UNBOUND_BLOCKED_DELIVERY_TOBEINVOICED Decimal(19, 4)
                    , FI_ANA_UNBOUND_BANK_DRAFT Decimal(19, 4)
                    , FI_ANA_UNBOUND_SALES Decimal(19, 4)
                    , FI_ANA_UNBOUND_PAYMENT Decimal(19, 4)
                    , FI_ANA_AGE_CUSTMMDE_PERIOD1 Decimal(19, 4)
                    , FI_ANA_AGE_CUSTMMDE_PERIOD2 Decimal(19, 4)
                    , FI_ANA_AGE_CUSTMMDE_PERIOD3 Decimal(19, 4)
                    , FI_ANA_AGE_CUSTMMDE_PERIOD4 Decimal(19, 4)
                    , FI_ANA_AGE_CUSTMMDE_DEBIT Decimal(19, 4)
                    , FI_ANA_AGE_CUSTMMDE_CREDIT Decimal(19, 4)
                    
                    , Index (MEMBERS_ID_MEMBERS)
                )
            ;
        Insert Into TMP_FIANA_MBRS_UPDATE  (
                    MEMBERS_ID_MEMBERS 
                    , FI_ANA_ACCOUNTS_COUNT 
                    , FI_ANA_ACCOUNTS_HASH
                    , FI_ANA_OUTSTANDING 
                    , FI_ANA_OVERDUE 
                    , FI_ANA_NOT_OVERDUE 
                    , FI_ANA_DUE 
                    , FI_ANA_FROZEN_AMOUNT 
                    , FI_ANA_BLOCKED_ALL 
                    , FI_ANA_BLOCKED_NOTOVERDUE 
                    , FI_ANA_AGE_PORTFOLIO_PERIOD1 
                    , FI_ANA_AGE_PORTFOLIO_PERIOD2 
                    , FI_ANA_AGE_PORTFOLIO_PERIOD3 
                    , FI_ANA_AGE_PORTFOLIO_PERIOD4 
                    , FI_ANA_AGE_PORTFOLIO_PERIOD5 
                    , FI_ANA_AGE_PORTFOLIO_PERIOD6 
                    , FI_ANA_AGE_PORTFOLIO_PERIOD7 
                    , FI_ANA_AGE_PORTFOLIO_PERIOD8 
                    , FI_ANA_AGE_ACCOUNT_PERIOD1 
                    , FI_ANA_AGE_ACCOUNT_PERIOD2 
                    , FI_ANA_AGE_ACCOUNT_PERIOD3 
                    , FI_ANA_AGE_ACCOUNT_PERIOD4  
                    , FI_ANA_CURRENT_ORDER_AMOUNT 
                    , FI_ANA_BLOCKED_ORDER_AMOUNT 
                    , FI_ANA_DELIVERY_TOBEINVOICED 
                    , FI_ANA_BLOCKED_DELIVERY_TOBEINVOICED 
                    , FI_ANA_BANK_DRAFT 
                    , FI_ANA_SALES 
                    , FI_ANA_PAYMENT 
                    , FI_ANA_UNBOUND_OUTSTANDING 
                    , FI_ANA_UNBOUND_OVERDUE 
                    , FI_ANA_UNBOUND_NOT_OVERDUE 
                    , FI_ANA_UNBOUND_DUE 
                    , FI_ANA_UNBOUND_FROZEN_AMOUNT 
                    , FI_ANA_UNBOUND_BLOCKED_ALL 
                    , FI_ANA_UNBOUND_BLOCKED_NOTOVERDUE 
                    , FI_ANA_UNBOUND_CURRENT_ORDER_AMOUNT 
                    , FI_ANA_UNBOUND_BLOCKED_ORDER_AMOUNT 
                    , FI_ANA_UNBOUND_DELIVERY_TOBEINVOICED 
                    , FI_ANA_UNBOUND_BLOCKED_DELIVERY_TOBEINVOICED 
                    , FI_ANA_UNBOUND_BANK_DRAFT 
                    , FI_ANA_UNBOUND_SALES 
                    , FI_ANA_UNBOUND_PAYMENT 
                    , FI_ANA_AGE_CUSTMMDE_PERIOD1 
                    , FI_ANA_AGE_CUSTMMDE_PERIOD2 
                    , FI_ANA_AGE_CUSTMMDE_PERIOD3 
                    , FI_ANA_AGE_CUSTMMDE_PERIOD4 
                    , FI_ANA_AGE_CUSTMMDE_DEBIT 
                    , FI_ANA_AGE_CUSTMMDE_CREDIT 
                    
                )
            -- explain
            Select
                FIMBR.MEMBERS_ID_MEMBERS
                , Count(FIACC.ACCOUNTS_ID_ACCOUNTS) FI_ANA_ACCOUNTS_COUNT
                , Md5(sum(FIACC.ACCOUNTS_ID_ACCOUNTS)) FI_ANA_ACCOUNTS_HASH
                , Sum(Coalesce(FIACC.FI_ANA_OUTSTANDING, 0)) FI_ANA_OUTSTANDING
                , Sum(Coalesce(FIACC.FI_ANA_OVERDUE, 0)) FI_ANA_OVERDUE
                , Sum(Coalesce(FIACC.FI_ANA_NOT_OVERDUE, 0)) FI_ANA_NOT_OVERDUE
                , Sum(Coalesce(FIACC.FI_ANA_DUE, 0)) FI_ANA_DUE
                , Sum(Coalesce(FIACC.FI_ANA_FROZEN_AMOUNT, 0)) FI_ANA_FROZEN_AMOUNT
                , Sum(Coalesce(FIACC.FI_ANA_BLOCKED_ALL, 0)) FI_ANA_BLOCKED_ALL
                , Sum(Coalesce(FIACC.FI_ANA_BLOCKED_NOTOVERDUE, 0)) FI_ANA_BLOCKED_NOTOVERDUE
                , Sum(Coalesce(FIACC.FI_ANA_AGE_PORTFOLIO_PERIOD1, 0)) FI_ANA_AGE_PORTFOLIO_PERIOD1
                , Sum(Coalesce(FIACC.FI_ANA_AGE_PORTFOLIO_PERIOD2, 0)) FI_ANA_AGE_PORTFOLIO_PERIOD2
                , Sum(Coalesce(FIACC.FI_ANA_AGE_PORTFOLIO_PERIOD3, 0)) FI_ANA_AGE_PORTFOLIO_PERIOD3
                , Sum(Coalesce(FIACC.FI_ANA_AGE_PORTFOLIO_PERIOD4, 0)) FI_ANA_AGE_PORTFOLIO_PERIOD4
                , Sum(Coalesce(FIACC.FI_ANA_AGE_PORTFOLIO_PERIOD5, 0)) FI_ANA_AGE_PORTFOLIO_PERIOD5
                , Sum(Coalesce(FIACC.FI_ANA_AGE_PORTFOLIO_PERIOD6, 0)) FI_ANA_AGE_PORTFOLIO_PERIOD6
                , Sum(Coalesce(FIACC.FI_ANA_AGE_PORTFOLIO_PERIOD7, 0)) FI_ANA_AGE_PORTFOLIO_PERIOD7
                , Sum(Coalesce(FIACC.FI_ANA_AGE_PORTFOLIO_PERIOD8, 0)) FI_ANA_AGE_PORTFOLIO_PERIOD8
                , Sum(Coalesce(FIACC.FI_ANA_AGE_ACCOUNT_PERIOD1, 0)) FI_ANA_AGE_ACCOUNT_PERIOD1
                , Sum(Coalesce(FIACC.FI_ANA_AGE_ACCOUNT_PERIOD2, 0)) FI_ANA_AGE_ACCOUNT_PERIOD2
                , Sum(Coalesce(FIACC.FI_ANA_AGE_ACCOUNT_PERIOD3, 0)) FI_ANA_AGE_ACCOUNT_PERIOD3
                , Sum(Coalesce(FIACC.FI_ANA_AGE_ACCOUNT_PERIOD4, 0)) FI_ANA_AGE_ACCOUNT_PERIOD4
                , Sum(Coalesce(FIACC.FI_ANA_CURRENT_ORDER_AMOUNT, 0)) FI_ANA_CURRENT_ORDER_AMOUNT
                , Sum(Coalesce(FIACC.FI_ANA_BLOCKED_ORDER_AMOUNT, 0)) FI_ANA_BLOCKED_ORDER_AMOUNT
                , Sum(Coalesce(FIACC.FI_ANA_DELIVERY_TOBEINVOICED, 0)) FI_ANA_DELIVERY_TOBEINVOICED
                , Sum(Coalesce(FIACC.FI_ANA_BLOCKED_DELIVERY_TOBEINVOICED, 0)) FI_ANA_BLOCKED_DELIVERY_TOBEINVOICED
                , Sum(Coalesce(FIACC.FI_ANA_BANK_DRAFT, 0)) FI_ANA_BANK_DRAFT
                , Sum(Coalesce(FIACC.FI_ANA_SALES, 0)) FI_ANA_SALES
                , Sum(Coalesce(FIACC.FI_ANA_PAYMENT, 0)) FI_ANA_PAYMENT
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_OUTSTANDING, 0)) FI_ANA_UNBOUND_OUTSTANDING
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_OVERDUE, 0)) FI_ANA_UNBOUND_OVERDUE
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_NOT_OVERDUE, 0)) FI_ANA_UNBOUND_NOT_OVERDUE
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_DUE, 0)) FI_ANA_UNBOUND_DUE
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_FROZEN_AMOUNT, 0)) FI_ANA_UNBOUND_FROZEN_AMOUNT
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_BLOCKED_ALL, 0)) FI_ANA_UNBOUND_BLOCKED_ALL
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_BLOCKED_NOTOVERDUE, 0)) FI_ANA_UNBOUND_BLOCKED_NOTOVERDUE
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_CURRENT_ORDER_AMOUNT, 0)) FI_ANA_UNBOUND_CURRENT_ORDER_AMOUNT
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_BLOCKED_ORDER_AMOUNT, 0)) FI_ANA_UNBOUND_BLOCKED_ORDER_AMOUNT
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_DELIVERY_TOBEINVOICED, 0)) FI_ANA_UNBOUND_DELIVERY_TOBEINVOICED
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_BLOCKED_DELIVERY_TOBEINVOICED, 0)) FI_ANA_UNBOUND_BLOCKED_DELIVERY_TOBEINVOICED
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_BANK_DRAFT, 0)) FI_ANA_UNBOUND_BANK_DRAFT
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_SALES, 0)) FI_ANA_UNBOUND_SALES
                , Sum(Coalesce(FIACC.FI_ANA_UNBOUND_PAYMENT, 0)) FI_ANA_UNBOUND_PAYMENT
                , Sum(Coalesce(FIACC.FI_ANA_AGE_CUSTMMDE_PERIOD1, 0)) FI_ANA_AGE_CUSTMMDE_PERIOD1
                , Sum(Coalesce(FIACC.FI_ANA_AGE_CUSTMMDE_PERIOD2, 0)) FI_ANA_AGE_CUSTMMDE_PERIOD2
                , Sum(Coalesce(FIACC.FI_ANA_AGE_CUSTMMDE_PERIOD3, 0)) FI_ANA_AGE_CUSTMMDE_PERIOD3
                , Sum(Coalesce(FIACC.FI_ANA_AGE_CUSTMMDE_PERIOD4, 0)) FI_ANA_AGE_CUSTMMDE_PERIOD4
                , Sum(Coalesce(FIACC.FI_ANA_AGE_CUSTMMDE_DEBIT, 0)) FI_ANA_AGE_CUSTMMDE_DEBIT
                , Sum(Coalesce(FIACC.FI_ANA_AGE_CUSTMMDE_CREDIT, 0)) FI_ANA_AGE_CUSTMMDE_CREDIT

            From
                FI_ANA_MEMBERS FIMBR
                Left Join (
					TMP_ACCOUNTS_CREDENTIALS_MEMBER__ALL CRED
					Inner Join FI_ANA FIACC	
						On FIACC.ACCOUNTS_ID_ACCOUNTS = CRED.ACCOUNTS_ID_ACCOUNTS
				)
                    On CRED.MEMBERS_ID_MEMBERS = FIMBR.MEMBERS_ID_MEMBERS
                
            Where 
--                 FIMBR.MEMBERS_ID_MEMBERS Like memberFilter
                FIMBR.MEMBERS_ID_MEMBERS Between @bufm_idmembers_min And @bufm_idmembers_max
            Group By 
                FIMBR.MEMBERS_ID_MEMBERS
        ;
    
-- 		Alter Table TMP_FIANA_MBRS_UPDATE
-- 				add index IX_TMP_FIANA_MBRS_UPDATE_01(MEMBERS_ID_MEMBERS)
-- 			;

        -- explain
        Update 
            FI_ANA_MEMBERS FIMBR
            Inner Join TMP_FIANA_MBRS_UPDATE FITMP
                On FITMP.MEMBERS_ID_MEMBERS = FIMBR.MEMBERS_ID_MEMBERS
        Set
            FIMBR.FI_ANA_ACCOUNTS_COUNT = FITMP.FI_ANA_ACCOUNTS_COUNT
            , FIMBR.FI_ANA_ACCOUNTS_HASH = FITMP.FI_ANA_ACCOUNTS_HASH
               , FIMBR.FI_ANA_OUTSTANDING = FITMP.FI_ANA_OUTSTANDING
               , FIMBR.FI_ANA_OVERDUE = FITMP.FI_ANA_OVERDUE
               , FIMBR.FI_ANA_NOT_OVERDUE = FITMP.FI_ANA_NOT_OVERDUE
               , FIMBR.FI_ANA_DUE = FITMP.FI_ANA_DUE
               , FIMBR.FI_ANA_FROZEN_AMOUNT = FITMP.FI_ANA_FROZEN_AMOUNT
               , FIMBR.FI_ANA_BLOCKED_ALL = FITMP.FI_ANA_BLOCKED_ALL
               , FIMBR.FI_ANA_BLOCKED_NOTOVERDUE = FITMP.FI_ANA_BLOCKED_NOTOVERDUE
               , FIMBR.FI_ANA_AGE_PORTFOLIO_PERIOD1 = FITMP.FI_ANA_AGE_PORTFOLIO_PERIOD1
               , FIMBR.FI_ANA_AGE_PORTFOLIO_PERIOD2 = FITMP.FI_ANA_AGE_PORTFOLIO_PERIOD2
               , FIMBR.FI_ANA_AGE_PORTFOLIO_PERIOD3 = FITMP.FI_ANA_AGE_PORTFOLIO_PERIOD3
               , FIMBR.FI_ANA_AGE_PORTFOLIO_PERIOD4 = FITMP.FI_ANA_AGE_PORTFOLIO_PERIOD4
               , FIMBR.FI_ANA_AGE_PORTFOLIO_PERIOD5 = FITMP.FI_ANA_AGE_PORTFOLIO_PERIOD5
               , FIMBR.FI_ANA_AGE_PORTFOLIO_PERIOD6 = FITMP.FI_ANA_AGE_PORTFOLIO_PERIOD6
               , FIMBR.FI_ANA_AGE_PORTFOLIO_PERIOD7 = FITMP.FI_ANA_AGE_PORTFOLIO_PERIOD7
               , FIMBR.FI_ANA_AGE_PORTFOLIO_PERIOD8 = FITMP.FI_ANA_AGE_PORTFOLIO_PERIOD8
               , FIMBR.FI_ANA_AGE_ACCOUNT_PERIOD1 = FITMP.FI_ANA_AGE_ACCOUNT_PERIOD1
               , FIMBR.FI_ANA_AGE_ACCOUNT_PERIOD2 = FITMP.FI_ANA_AGE_ACCOUNT_PERIOD2
               , FIMBR.FI_ANA_AGE_ACCOUNT_PERIOD3 = FITMP.FI_ANA_AGE_ACCOUNT_PERIOD3
               , FIMBR.FI_ANA_AGE_ACCOUNT_PERIOD4 = FITMP.FI_ANA_AGE_ACCOUNT_PERIOD4
               , FIMBR.FI_ANA_CURRENT_ORDER_AMOUNT = FITMP.FI_ANA_CURRENT_ORDER_AMOUNT
               , FIMBR.FI_ANA_BLOCKED_ORDER_AMOUNT = FITMP.FI_ANA_BLOCKED_ORDER_AMOUNT
               , FIMBR.FI_ANA_DELIVERY_TOBEINVOICED = FITMP.FI_ANA_DELIVERY_TOBEINVOICED
               , FIMBR.FI_ANA_BLOCKED_DELIVERY_TOBEINVOICED = FITMP.FI_ANA_BLOCKED_DELIVERY_TOBEINVOICED
               , FIMBR.FI_ANA_BANK_DRAFT = FITMP.FI_ANA_BANK_DRAFT
               , FIMBR.FI_ANA_SALES = FITMP.FI_ANA_SALES
               , FIMBR.FI_ANA_PAYMENT = FITMP.FI_ANA_PAYMENT
               , FIMBR.FI_ANA_UNBOUND_OUTSTANDING = FITMP.FI_ANA_UNBOUND_OUTSTANDING
               , FIMBR.FI_ANA_UNBOUND_OVERDUE = FITMP.FI_ANA_UNBOUND_OVERDUE
               , FIMBR.FI_ANA_UNBOUND_NOT_OVERDUE = FITMP.FI_ANA_UNBOUND_NOT_OVERDUE
               , FIMBR.FI_ANA_UNBOUND_DUE = FITMP.FI_ANA_UNBOUND_DUE
               , FIMBR.FI_ANA_UNBOUND_FROZEN_AMOUNT = FITMP.FI_ANA_UNBOUND_FROZEN_AMOUNT
               , FIMBR.FI_ANA_UNBOUND_BLOCKED_ALL = FITMP.FI_ANA_UNBOUND_BLOCKED_ALL
               , FIMBR.FI_ANA_UNBOUND_BLOCKED_NOTOVERDUE = FITMP.FI_ANA_UNBOUND_BLOCKED_NOTOVERDUE
               , FIMBR.FI_ANA_UNBOUND_CURRENT_ORDER_AMOUNT = FITMP.FI_ANA_UNBOUND_CURRENT_ORDER_AMOUNT
               , FIMBR.FI_ANA_UNBOUND_BLOCKED_ORDER_AMOUNT = FITMP.FI_ANA_UNBOUND_BLOCKED_ORDER_AMOUNT
               , FIMBR.FI_ANA_UNBOUND_DELIVERY_TOBEINVOICED = FITMP.FI_ANA_UNBOUND_DELIVERY_TOBEINVOICED
               , FIMBR.FI_ANA_UNBOUND_BLOCKED_DELIVERY_TOBEINVOICED = FITMP.FI_ANA_UNBOUND_BLOCKED_DELIVERY_TOBEINVOICED
               , FIMBR.FI_ANA_UNBOUND_BANK_DRAFT = FITMP.FI_ANA_UNBOUND_BANK_DRAFT
               , FIMBR.FI_ANA_UNBOUND_SALES = FITMP.FI_ANA_UNBOUND_SALES
               , FIMBR.FI_ANA_UNBOUND_PAYMENT = FITMP.FI_ANA_UNBOUND_PAYMENT
               , FIMBR.FI_ANA_AGE_CUSTMMDE_PERIOD1 = FITMP.FI_ANA_AGE_CUSTMMDE_PERIOD1
               , FIMBR.FI_ANA_AGE_CUSTMMDE_PERIOD2 = FITMP.FI_ANA_AGE_CUSTMMDE_PERIOD2
               , FIMBR.FI_ANA_AGE_CUSTMMDE_PERIOD3 = FITMP.FI_ANA_AGE_CUSTMMDE_PERIOD3
               , FIMBR.FI_ANA_AGE_CUSTMMDE_PERIOD4 = FITMP.FI_ANA_AGE_CUSTMMDE_PERIOD4
               , FIMBR.FI_ANA_AGE_CUSTMMDE_DEBIT = FITMP.FI_ANA_AGE_CUSTMMDE_DEBIT
               , FIMBR.FI_ANA_AGE_CUSTMMDE_CREDIT = FITMP.FI_ANA_AGE_CUSTMMDE_CREDIT
        ;

        Drop Temporary Table If Exists TMP_FIANA_MBRS_UPDATE;
        
    End;

End //
Delimiter ;