|
21 | 21 | additional fields (telephone Number, etc). |
22 | 22 |
|
23 | 23 | 23/12/2024 - Create SQL |
| 24 | +06/01/2025 - add unsubscribed email |
| 25 | +13/01/2025 - add opt-in data |
24 | 26 | *********************************************************************************/ |
25 | 27 | With Interim_Wait as ( |
26 | 28 | SELECT |
|
61 | 63 | From "dataplatform-stg-liberator-raw-zone".liberator_licence_party |
62 | 64 | WHERE import_Date = format_datetime(current_date, 'yyyyMMdd')), |
63 | 65 |
|
64 | | -/*** obtain the emails (from Tom) of those parties that are NOT interested in a Hangar***/ |
| 66 | +/*** 06/01/2024 - obtain the emails (from Tom) of those parties that are NOT interested in a Hangar***/ |
65 | 67 | unsubscribed_emails as ( |
66 | 68 | SELECT *, |
67 | 69 | ROW_NUMBER() OVER ( PARTITION BY email_address ORDER BY email_address DESC) row1 |
68 | 70 | FROM "parking-raw-zone".parking_parking_cycle_hangar_unsubscribed_emails |
69 | 71 | WHERE import_date = (select max(import_date) |
70 | | - from "parking-raw-zone".parking_parking_cycle_hangar_unsubscribed_emails)) |
| 72 | + from "parking-raw-zone".parking_parking_cycle_hangar_unsubscribed_emails)), |
| 73 | +
|
| 74 | +/*** 13/01/2025 added ***/ |
| 75 | +opt_in_emails as ( |
| 76 | + SELECT |
| 77 | + please_note_your_email_address_has_been_prefilled_based_on_your_account_registration_please_do_not_amend_this as email, |
| 78 | + please_select_one_of_the_options_below, |
| 79 | + ROW_NUMBER() OVER ( PARTITION BY please_note_your_email_address_has_been_prefilled_based_on_your_account_registration_please_do_not_amend_this |
| 80 | + ORDER BY please_note_your_email_address_has_been_prefilled_based_on_your_account_registration_please_do_not_amend_this |
| 81 | + DESC) row1 |
| 82 | + FROM "parking-raw-zone".parking_parking_opt_in_form_responses |
| 83 | + WHERE import_date = (select max(import_date) |
| 84 | + from "parking-raw-zone".parking_parking_opt_in_form_responses) |
| 85 | + AND please_select_one_of_the_options_below like 'No.%') |
71 | 86 |
|
72 | 87 | SELECT |
73 | | - A.*, cast(D.telephone_number as varchar) as Telephone_Number, C.address2 as Street, B.housing_estate, E.email_address, |
| 88 | + A.*, cast(D.telephone_number as varchar) as Telephone_Number, C.address2 as Street, B.housing_estate, |
| 89 | + CASE |
| 90 | + When length(E.email_address) > 1 Then E.email_address |
| 91 | + When length(F.email)> 1 Then F.email |
| 92 | + END as email_address, |
74 | 93 |
|
75 | 94 | format_datetime(CAST(CURRENT_TIMESTAMP AS timestamp), |
76 | 95 | 'yyyy-MM-dd HH:mm:ss') AS import_date_timestamp, |
|
85 | 104 | LEFT JOIN STREET_LLPG as C ON B.USRN = C.USRN |
86 | 105 | LEFT JOIN Party as D ON A.party_id = D.business_party_id |
87 | 106 | LEFT JOIN unsubscribed_emails as E ON upper(ltrim(rtrim(A.email))) = upper(ltrim(rtrim(E.email_address))) |
88 | | - AND row1 = 1 |
| 107 | + AND E.row1 = 1 |
| 108 | +LEFT JOIN opt_in_emails as F ON upper(ltrim(rtrim(A.email))) = upper(ltrim(rtrim(F.email))) |
| 109 | + AND F.row1 = 1 |
89 | 110 | """ |
90 | 111 |
|
91 | 112 | create_update_table_with_partition( |
|
0 commit comments