Delimiter //
/**
 * Author:  armen
 * Created: 19 mai 2022
 */

Drop Procedure If Exists BUSINESS_TEMPLATE_LOADER_CP_PAYMNT_TYPES //
Create Procedure BUSINESS_TEMPLATE_LOADER_CP_PAYMNT_TYPES(
    In srcTemplaterLoaderId int
    , In tarTemplaterLoaderId int
)
Begin
    Main: Begin
        Insert Into TEMPL_LOADER_has_DF_PAY_TYPE (
            TEMPL_LOADER_ID_TEMPL_LOADER, DF_PAY_TYPE_ID_DF_PAY_TYPE, TEMPL_LOADER_DF_PAY_TYPE_CODE
        )
        select
               tarTemplaterLoaderId, src.DF_PAY_TYPE_ID_DF_PAY_TYPE, src.TEMPL_LOADER_DF_PAY_TYPE_CODE
        from TEMPL_LOADER_has_DF_PAY_TYPE src
            Left Join TEMPL_LOADER_has_DF_PAY_TYPE tar
                On src.TEMPL_LOADER_DF_PAY_TYPE_CODE = tar.TEMPL_LOADER_DF_PAY_TYPE_CODE
                And tar.TEMPL_LOADER_ID_TEMPL_LOADER = tarTemplaterLoaderId
        Where src.TEMPL_LOADER_ID_TEMPL_LOADER = srcTemplaterLoaderId
            and tar.ID_TEMPL_LOADER_has_DF_PAY_TYP is null
        ;
    End;
End //

Delimiter ;