Delimiter //
/**
 * Author:  armen
 * Created: 26 févr. 2018
 * @see BUSINESS_UPDATE_FIANA
 * @see BUSINESS_FI_ANA_INSERT_NEW_ACCOUNTS
 * @see BUSINESS_BACKUP_FIANA
 */
Drop Procedure if exists LOADER_ACCOUNTS_COPY_FIANA_UPDATE//
Create Procedure LOADER_ACCOUNTS_COPY_FIANA_UPDATE (
    In batchnum int
)
Begin
        Update 
            FI_ANA trgt 
            Inner Join LOADER_ACCOUNTS src 
                On trgt.ACCOUNTS_ID_ACCOUNTS = src.ID_ACCOUNTS 
            Inner Join LOADER_STATUS lst 
                On src.LOADER_STATUS_ID_LOADER_STATUS = lst.ID_LOADER_STATUS 
        Set 

            trgt.FI_ANA_CASH_ASSESSMENT = Coalesce(src.FI_ANA_CASH_ASSESSMENT , trgt.FI_ANA_CASH_ASSESSMENT)
            , trgt.FI_ANA_CASH_ASSSSMNTLASTUPDAT = Coalesce(src.FI_ANA_CASH_ASSSSMNTLASTUPDAT , trgt.FI_ANA_CASH_ASSSSMNTLASTUPDAT)

            , trgt.FI_ANA_INTERNAL_SCORE_RATING = Coalesce(src.FI_ANA_INTERNAL_SCORE_RATING , trgt.FI_ANA_INTERNAL_SCORE_RATING)
            , trgt.FI_ANA_INTRSCORRATLASTUPDAT = Coalesce(src.FI_ANA_INTRSCORRATLASTUPDAT , trgt.FI_ANA_INTRSCORRATLASTUPDAT)

            , trgt.FI_ANA_EXTERNAL_SCORE_RATING = Coalesce(src.FI_ANA_EXTERNAL_SCORE_RATING , trgt.FI_ANA_EXTERNAL_SCORE_RATING)
            , trgt.FI_ANA_EXTSCORRATLASTUPDAT = Coalesce(src.FI_ANA_EXTSCORRATLASTUPDAT , trgt.FI_ANA_EXTSCORRATLASTUPDAT)

       Where 1 = 1 
            And lst.LOADER_STATUS_ERRCOUNT = 0 
            And lst.LOADER_STATUS_BATCH_NUM =  batchnum
            -- And and Coalesce(src.ID_ACCOUNTS, 0) <> 0 -- implicite
        ;
End //

Delimiter ;
