Files
workspace/skills/dbt-create-transform/trf_template.sql
@gabriel.pereira 5c4e6075e1 add claude skills
2026-03-26 16:29:53 -03:00

45 lines
1.3 KiB
SQL

{{ config(
materialized = 'incremental',
unique_key = ['KEY_COL_1', 'KEY_COL_2'],
on_schema_change = 'sync_all_columns',
incremental_strategy = 'delete+insert'
) }}
{{- sie_dbt_utils.full_refresh_protection() -}}
-- remove the line above if sie_dbt_utils is not available
with
base_table as (
select *
from {{ ref('stg_<system>_<table>') }}
where mandt in ('022', '100') -- replace with your tenant/client filter
),
related_table as (
select *
from {{ ref('stg_<system>_<other_table>') }}
),
final as (
select
base_table.COLUMN_1 as READABLE_COLUMN_1,
base_table.COLUMN_2 as READABLE_COLUMN_2,
related_table.COLUMN_A as READABLE_COLUMN_A
from base_table
left join related_table
on base_table.join_key = related_table.join_key
where year(dateadd(month, 3, to_date(base_table.date_col, 'yyyymmdd')))
>= year(dateadd(year, -2, dateadd(month, 3, getdate())))
-- ^ Siemens fiscal year filter (FY = calendar year + 3 months)
-- Replace with your project's date filter logic
{% if is_incremental() %}
and year(dateadd(month, 3, to_date(base_table.date_col, 'yyyymmdd')))
<= year(add_months(current_date(), 3))
{% endif %}
)
select * from final