From 99313fc9637eac31bd02cfc5112d6ee9c4d35024 Mon Sep 17 00:00:00 2001 From: Anthony Walters Date: Thu, 21 Nov 2024 18:27:14 +0000 Subject: [PATCH] add sw referral date to cn view --- .../rpt_tableau__kfwd_contact_notes.sql | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__kfwd_contact_notes.sql b/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__kfwd_contact_notes.sql index 5b50c93d6..a6e6db24a 100644 --- a/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__kfwd_contact_notes.sql +++ b/src/dbt/kipptaf/models/extracts/tableau/rpt_tableau__kfwd_contact_notes.sql @@ -1,3 +1,17 @@ +with + sw_referral as ( + select + contact, + academic_year, + date, + + row_number() over ( + partition by contact, academic_year order by date desc + ) as rn_referral, + from {{ ref("stg_kippadb__contact_note") }} + where subject in ('SW REM Referral', 'SW Teammate Referral', 'SW Self Referral') + ) + select ktc.contact_id as sf_contact_id, ktc.first_name, @@ -22,5 +36,12 @@ select cn.status, cn.type, cn.academic_year, + + sw.date as referral_date, from {{ ref("int_kippadb__roster") }} as ktc inner join {{ ref("stg_kippadb__contact_note") }} as cn on ktc.contact_id = cn.contact +left join + sw_referral as sw + on cn.contact = sw.contact + and cn.academic_year = sw.academic_year + and sw.rn_referral = 1