{% macro insert_A_TASK_HISTORY_TARGET(a_task_history_key, model_name, status, rows_affected) %}

{% if execute %}

    {% set insert_A_TASK_HISTORY_TARGET %}
        INSERT INTO {{ source('control_tables','A_TASK_HISTORY_TARGET') }} (A_TASK_HISTORY_TARGET_KEY, A_TASK_HISTORY_KEY, TARGET_NAME, ROW_COUNT_APPLIED, LOAD_SUCCESSFUL, SERVICE_NAME)
        VALUES ({{ source('control_sequences','A_TASK_HISTORY_TARGET_SEQ') }}.NEXTVAL, {{ a_task_history_key }}, '{{ model_name }}', {{ rows_affected }}, '{{ status }}', '{{ var("input_service_name") }}')
    {% endset %}

    {% do run_query(insert_A_TASK_HISTORY_TARGET) %}

{% endif %}
{% endmacro %}