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 · key | customer_idtext | countrytext | valid_fromtext | valid_totext |
|---|---|---|---|---|
| 101 | C001 | United States | 2024-01-01 | 2025-02-01 |
| 102 | C001 | Canada | 2025-02-01 | NULL |
| 103 | C002 | United Kingdom | 2024-01-01 | NULL |
all 3 rows
dim_customer4 columns · 5 rows
| customer_keyinteger · key | customer_idtext | nametext | countrytext |
|---|---|---|---|
| 1 | C001 | Alice Nguyen | United States |
| 2 | C002 | Ben | United Kingdom |
| 3 | C003 | Cara | United Kingdom |
| 4 | C004 | Dev | India |
| 5 | C005 | Elena | Canada |
all 5 rows