|
21 | 21 | Code has been switched the use of the raw vrm and vrm update tables to the 480 raw tables |
22 | 22 |
|
23 | 23 | 02/09/2024 - Create query from 'parking_permit_denormalisation' |
| 24 | +30/10/2024 - add code to remove the dupliacte records |
24 | 25 | ****************************************************************************************************************/ |
25 | 26 | /*** Obtain the Permits start/finish for FTA and renewals ***/ |
26 | 27 | With PermitStartFinishBEFORE as ( |
|
490 | 491 | A.permit_reference not like 'HYF%' AND |
491 | 492 | A.permit_reference not like 'HYJ%' AND |
492 | 493 | A.permit_reference not like 'HYE%' AND |
493 | | - (renewal_start_date != '' OR renewal_end_date != '')) |
| 494 | + (renewal_start_date != '' OR renewal_end_date != '')), |
494 | 495 | |
495 | 496 | /******************************************************************************************************************/ |
496 | 497 | /*** Finally output the data, WITH The VRM details **/ |
497 | | -SELECT |
| 498 | +/*** 30-10-2024 add code to remove the duplicates ***/ |
| 499 | +Output as ( |
| 500 | + SELECT |
498 | 501 | A.permit_reference, A.application_date, A.forename_of_applicant, A.surname_of_applicant, |
499 | 502 | A.email_address_of_applicant, A.primary_phone, A.secondary_phone, A.date_of_birth_of_applicant, |
500 | 503 | A.blue_badge_number, A.blue_badge_expiry, A.start_date, A.end_date, A.approval_date, |
|
519 | 522 | Else '' |
520 | 523 | END as Fin_Year_Flag, |
521 | 524 | /** Financial Year **/ |
522 | | - Fin_Year, |
523 | | - |
524 | | - usrn, |
| 525 | + Fin_Year, usrn |
| 526 | + From Permits as A |
| 527 | + LEFT JOIN VRMDetails as B ON A.permit_reference = B.permit_reference AND A.vrm = B.vrm and B.row_num = 1 |
| 528 | + LEFT JOIN CalendarFormat as F ON CAST(A.application_date as date) = date and F.row_num = 1 |
| 529 | + LEFT JOIN LLPG_USRN as G ON A.uprn = G.uprn |
| 530 | + Where A.Rn = 1) |
| 531 | + |
| 532 | +/*** Output the deduped data ***/ |
| 533 | +SELECT |
| 534 | + permit_reference, application_date, forename_of_applicant, surname_of_applicant, |
| 535 | + email_address_of_applicant, primary_phone, secondary_phone, date_of_birth_of_applicant, |
| 536 | + blue_badge_number, blue_badge_expiry, start_date, end_date, approval_date, |
| 537 | + approved_by, approval_type, amount, payment_date, payment_method, payment_location, |
| 538 | + payment_by, payment_received, directorate_to_be_charged, authorising_officer, |
| 539 | + cost_code, subjective_code, permit_type, ordered_by, business_name, hasc_organisation_name, |
| 540 | + doctors_surgery_name, number_of_bays, number_of_days, number_of_dispensation_vehicles, |
| 541 | + dispensation_reason, uprn, address_line_1, address_line_2, address_line_3, postcode, |
| 542 | + cpz, cpz_name, status, quantity, vrm, associated_to_order, Live_Permit_Flag, |
| 543 | + Permit_Fta_Renewal, Latest_Permit_Status, cpz_code, |
| 544 | + make, model, fuel, engine_capactiy, co2_emission, foreign, lpg_conversion, VRM_record_created, |
| 545 | + is_motorcycle, Fin_Year_Flag, Fin_Year, usrn, |
525 | 546 |
|
526 | | - --current_timestamp as ImportDateTime, |
527 | | - |
528 | 547 | format_datetime(current_date, 'yyyy') AS import_year, |
529 | 548 | format_datetime(current_date, 'MM') AS import_month, |
530 | 549 | format_datetime(current_date, 'dd') AS import_day, |
531 | 550 | format_datetime(current_date, 'yyyyMMdd') AS import_date |
532 | | - |
533 | | -From Permits as A |
534 | | -LEFT JOIN VRMDetails as B ON A.permit_reference = B.permit_reference AND A.vrm = B.vrm and B.row_num = 1 |
535 | | -LEFT JOIN CalendarFormat as F ON CAST(A.application_date as date) = date and F.row_num = 1 |
536 | | -LEFT JOIN LLPG_USRN as G ON A.uprn = G.uprn |
537 | | -Where A.Rn = 1 |
| 551 | +FROM Output |
| 552 | +WHERE R1 = 1 |
538 | 553 | """ |
539 | 554 |
|
540 | 555 | create_update_table_with_partition( |
|
0 commit comments