diff --git a/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql b/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql index 04a75d45..785f509a 100644 --- a/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql +++ b/models/br_ms_sia/br_ms_sia__producao_ambulatorial.sql @@ -238,6 +238,8 @@ select * from sia {% if is_incremental() %} - where date(cast(ano as int64), cast(mes as int64), 1) > date(2024, 3, 1) + where + date(cast(ano as int64), cast(mes as int64), 1) + > (select max(date(cast(ano as int64), cast(mes as int64), 1)) from {{ this }}) {% endif %} diff --git a/models/br_ms_sia/br_ms_sia__psicossocial.sql b/models/br_ms_sia/br_ms_sia__psicossocial.sql index 6d43ae0a..920be430 100644 --- a/models/br_ms_sia/br_ms_sia__psicossocial.sql +++ b/models/br_ms_sia/br_ms_sia__psicossocial.sql @@ -148,5 +148,7 @@ select safe_cast(qtdpcn as string) quantidade_pacientes, from sia_add_municipios as t {% if is_incremental() %} - where date(cast(ano as int64), cast(mes as int64), 1) > date(2024, 3, 1) + where + date(cast(ano as int64), cast(mes as int64), 1) + > (select max(date(cast(ano as int64), cast(mes as int64), 1)) from {{ this }}) {% endif %}