runtime
CRM + ERP Integration · milestone 08 / 12

milestone 8/12 Latest-state reporting versus SCD Type 2

Compare current-state reporting with preserved history.

CRM + ERP Integration · Follow extraction reconciliation, authoritative integration, date quarantine, quality gates, stable keys, replay-safe loads, and atomic promotion. Finish with a customer-grain capstone and field-level lineage.

approach

The foundational project keeps latest state. Type 1 overwrites attributes; Type 2 retains effective versions with distinct keys. Decide whether a report means current classification or classification at event time. Here customer_history uses nonoverlapping half-open validity ranges; NULL end means current.

worked-example.sql
SELECT customer_id,country
FROM customer_history
WHERE valid_to IS NULL;

data for this milestone

customer_history5 columns · 3 rows
version_keyinteger · keycustomer_idtextcountrytextvalid_fromtextvalid_totext
101C001United States2024-01-012025-02-01
102C001Canada2025-02-01NULL
103C002United Kingdom2024-01-01NULL

all 3 rows

dim_customer4 columns · 5 rows
customer_keyinteger · keycustomer_idtextnametextcountrytext
1C001Alice NguyenUnited States
2C002BenUnited Kingdom
3C003CaraUnited Kingdom
4C004DevIndia
5C005ElenaCanada

all 5 rows

challenge 1

Return customer_id,country for the current version of every customer_history customer.

what to return

Columns
customer_idcountry in this order
Rows
any order
challenge-1.sql
 
3 steps left · check both queries and pass the concept checkOpen the reportNext milestone
Latest-state reporting versus SCD Type 2 — CRM + ERP Integration · Runtime