silver.load_silver() stored procedure.
CRM Transformations
Customer Information (crm_cust_info)
Transformations applied to customer data include:String Trimming
String Trimming
All string fields are trimmed to remove leading/trailing whitespace:
- Customer key
- First name
- Last name
Marital Status Standardization
Marital Status Standardization
Single-character codes are expanded to full words:
'S'→'Single''M'→'Married'- All other values →
'n/a'
Gender Standardization
Gender Standardization
Single-character codes are expanded to full words:
'M'→'Male''F'→'Female'- All other values →
'n/a'
Deduplication
Deduplication
Only the most recent record per customer is kept:Uses window function to identify and select only the latest record based on
cst_create_date.Complete Transformation SQL
Product Information (crm_prd_info)
Transformations applied to product data:Category ID Extraction
Category ID Extraction
Category ID is extracted from the product key and formatted:
- Takes first 5 characters of product key
- Replaces hyphens with underscores
- Example:
'AR-12'→'AR_12'
Product Key Parsing
Product Key Parsing
Product key is extracted from position 7 onwards:
Cost Null Handling
Cost Null Handling
Null costs are replaced with 0:
Product Line Standardization
Product Line Standardization
Single-character product line codes are expanded:
'M'→'Mountain''R'→'Road''S'→'Other sales''T'→'Touring'- All other values →
'n/a'
End Date Calculation
End Date Calculation
Product end date is calculated using the next product’s start date:Uses LEAD window function to get the next version’s start date minus 1 day.
Complete Transformation SQL
Sales Details (crm_sales_details)
Comprehensive data quality checks and corrections for sales transactions:Date Validation & Conversion
Date Validation & Conversion
All date fields are validated before conversion from YYYYMMDD format:Checks applied:
- Not null
- Not zero
- Exactly 8 characters
- If invalid, set to NULL
sls_ord_dt, sls_ship_dt, sls_due_dtSales Amount Correction
Sales Amount Correction
Sales amount is recalculated if inconsistent:Recalculates when:
- Sales is null
- Sales is zero or negative
- Sales doesn’t match
quantity × price
Price Validation & Correction
Price Validation & Correction
Unit price is validated and corrected:Logic:
- If price is null/zero/negative: derive from
sales ÷ quantity - If price is negative: convert to absolute value
- Otherwise: use original price
Complete Transformation SQL
ERP Transformations
ERP Customer Data (erp_cust_az12)
Customer ID Cleaning
Customer ID Cleaning
Removes ‘NAS’ prefix from customer IDs:
Birth Date Validation
Birth Date Validation
Rejects future birth dates:
Gender Standardization
Gender Standardization
Standardizes gender values (handles multiple formats):
'F'or'FEMALE'→'Female''M'or'MALE'→'Male'- All other values →
'n/a'
ERP Location Data (erp_loc_a101)
Customer ID Formatting
Customer ID Formatting
Removes hyphens from customer IDs:
Country Name Standardization
Country Name Standardization
Expands country codes to full names:
'USA','US'→'United States''CAN'→'Canada''DE'→'Germany'- Empty/null →
'n/a' - Other values passed through (trimmed)
ERP Product Category (erp_px_cat_g1v2)
Minimal transformation - data is loaded as-is from Bronze:No transformations are applied to this table - data quality is assumed to be high in the source system.
Execution
All transformations are executed via the stored procedure:- Truncates each Silver table before loading
- Processes tables sequentially with error handling
- Logs execution time for each step
- Grants public access to the schema and tables upon completion