Skip to content

Commit

Permalink
Update CustomerMgmtView.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
techvaquero authored Aug 2, 2023
1 parent 673b46e commit 8b62519
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions models/snowflake/base/CustomerMgmtView.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,56 @@
materialized = 'view'
)
}}
select
*
from
{{ source('tpcdi', 'CustomerMgmt') }}

SELECT
get(xmlget($1, 'Customer'), '@C_ID')::BIGINT as customerid,
get(xmlget(xmlget($1, 'Customer'), 'Account'), '@CA_ID')::BIGINT as accountid,
get(xmlget(xmlget(xmlget($1, 'Customer'), 'Account'), 'CA_B_ID'), '$')::BIGINT as brokerid,
nullif(get(xmlget($1, 'Customer'), '@C_TAX_ID'), '') as taxid,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Account'), 'CA_NAME'), '$'), '') as accountdesc,
get(xmlget(xmlget($1, 'Customer'), 'Account'), '@CA_TAX_ST')::TINYINT as taxstatus,
decode(get($1, '@ActionType'), 'NEW','Active', 'ADDACCT','Active', 'UPDACCT','Active', 'UPDCUST','Active', 'CLOSEACCT','Inactive', 'INACT','Inactive') as status,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Name'), 'C_L_NAME'), '$'), '') as lastname,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Name'), 'C_F_NAME'), '$'), '') as firstname,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Name'), 'C_M_NAME'), '$'), '') as middleinitial,
nullif(upper(get(xmlget($1, 'Customer'), '@C_GNDR')), '') as gender,
nullif(get(xmlget($1, 'Customer'), '@C_TIER'), '') as tier,
get(xmlget($1, 'Customer'), '@C_DOB')::DATE as dob,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_ADLINE1'), '$'), '') as addressline1,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_ADLINE2'), '$'), '') as addressline2,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_ZIPCODE'), '$'), '') as postalcode,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_CITY'), '$'), '') as city,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_STATE_PROV'), '$'), '') as stateprov,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'Address'), 'C_CTRY'), '$'), '') as country,
nvl2(
nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_LOCAL'), '$'), ''),
concat(
nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_CTRY_CODE'), '$'), ''), '+' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'CTRY_CODE'), '$') || ' ', ''),
nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_AREA_CODE'), '$'), ''), '(' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_AREA_CODE'), '$') || ') ', ''),
get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_LOCAL'), '$'),
nvl(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_1'), 'C_EXT'), '$'), '')),
cast(null as string)) phone1,
nvl2(
nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_LOCAL'), '$'), ''),
concat(
nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_CTRY_CODE'), '$'), ''), '+' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'CTRY_CODE'), '$') || ' ', ''),
nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_AREA_CODE'), '$'), ''), '(' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_AREA_CODE'), '$') || ') ', ''),
get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_LOCAL'), '$'),
nvl(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_2'), 'C_EXT'), '$'), '')),
cast(null as string)) phone2,
nvl2(
nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_LOCAL'), '$'), ''),
concat(
nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_CTRY_CODE'), '$'), ''), '+' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'CTRY_CODE'), '$') || ' ', ''),
nvl2(nullif(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_AREA_CODE'), '$'), ''), '(' || get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_AREA_CODE'), '$') || ') ', ''),
get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_LOCAL'), '$'),
nvl(get(xmlget(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PHONE_3'), 'C_EXT'), '$'), '')),
cast(null as string)) phone3,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_PRIM_EMAIL'), '$'), '') as email1,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'ContactInfo'), 'C_ALT_EMAIL'), '$'), '') as email2,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'TaxInfo'), 'C_LCL_TX_ID'), '$'), '') as lcl_tx_id,
nullif(get(xmlget(xmlget(xmlget($1, 'Customer'), 'TaxInfo'), 'C_NAT_TX_ID'), '$'), '') as nat_tx_id,
to_timestamp(get($1, '@ActionTS')) as update_ts,
get($1, '@ActionType') as ActionType
FROM @{{var('stage')}}/Batch1 (FILE_FORMAT => 'XML', PATTERN => '.*CustomerMgmt[.]xml.*')

0 comments on commit 8b62519

Please sign in to comment.