BEGIN TRY
    BEGIN TRANSACTION;

    /* =========================================
    1. Work Request - Original Priority
    ========================================= */
    SELECT 
        section_name          = '1. Work Request - Original Priority',
        d.site_cd,
        detail_value_original = d.wkr_mst_orig_priority,
        master_value_original = m.wrk_pri_pri_cd,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN wrk_pri m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_orig_priority) = RTRIM(m.wrk_pri_pri_cd)
    WHERE d.wkr_mst_orig_priority IS NOT NULL
      AND d.wkr_mst_orig_priority LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;

    --UPDATE d
    --   SET d.wkr_mst_orig_priority = (m.wrk_pri_pri_cd)
    --FROM wkr_mst d
    --INNER JOIN wrk_pri m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_orig_priority) = RTRIM(m.wrk_pri_pri_cd)
    --WHERE d.wkr_mst_orig_priority IS NOT NULL
    --  AND d.wkr_mst_orig_priority LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_orig_priority) <> DATALENGTH(RTRIM(m.wrk_pri_pri_cd));

    /* =========================================
    2. Work Request - Work Group
    ========================================= */
    SELECT 
        section_name          = '2. Work Request - Work Group',
        d.site_cd,
        detail_value_original = d.wkr_mst_work_group,
		master_value_original = m.wrk_grp_grp_cd,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN wrk_grp m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_work_group) = RTRIM(m.wrk_grp_grp_cd)
    WHERE d.wkr_mst_work_group IS NOT NULL
      AND d.wkr_mst_work_group LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;
	 
    --UPDATE d
    --   SET d.wkr_mst_work_group = (m.wrk_grp_grp_cd)
    --FROM wkr_mst d
    --INNER JOIN wrk_grp m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_work_group) = RTRIM(m.wrk_grp_grp_cd)
    --WHERE d.wkr_mst_work_group IS NOT NULL
    --  AND d.wkr_mst_work_group LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_work_group) <> DATALENGTH(RTRIM(m.wrk_grp_grp_cd));

    /* =========================================
    3. Work Request - Work Type
    ========================================= */
    SELECT 
        section_name          = '3. Work Request - Work Type',
        d.site_cd,
        detail_value_original = d.wkr_mst_work_type,
        master_value_original = m.wrk_typ_typ_cd,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN wrk_typ m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_work_type) = RTRIM(m.wrk_typ_typ_cd)
    WHERE d.wkr_mst_work_type IS NOT NULL
      AND d.wkr_mst_work_type LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;

    --UPDATE d
    --   SET d.wkr_mst_work_type = (m.wrk_typ_typ_cd)
    --FROM wkr_mst d
    --INNER JOIN wrk_typ m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_work_type) = RTRIM(m.wrk_typ_typ_cd)
    --WHERE d.wkr_mst_work_type IS NOT NULL
    --  AND d.wkr_mst_work_type LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_work_type) <> DATALENGTH(RTRIM(m.wrk_typ_typ_cd));

    /* =========================================
    4. Work Request - Work Class
    ========================================= */
    SELECT 
        section_name          = '4. Work Request - Work Class',
        d.site_cd,
        detail_value_original = d.wkr_mst_work_class,
		master_value_original = m.wrk_cls_cls_cd,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN wrk_cls m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_work_class) = RTRIM(m.wrk_cls_cls_cd)
    WHERE d.wkr_mst_work_class IS NOT NULL
      AND d.wkr_mst_work_class LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;

    --UPDATE d
    --   SET d.wkr_mst_work_class = (m.wrk_cls_cls_cd)
    --FROM wkr_mst d
    --INNER JOIN wrk_cls m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_work_class) = RTRIM(m.wrk_cls_cls_cd)
    --WHERE d.wkr_mst_work_class IS NOT NULL
    --  AND d.wkr_mst_work_class LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_work_class) <> DATALENGTH(RTRIM(m.wrk_cls_cls_cd));

    /* =========================================
    5. Work Request - Fault Code
    ========================================= */
    SELECT 
        section_name          = '5. Work Request - Fault Code',
        d.site_cd,
        detail_value_original = d.wkr_mst_fault_code,
        master_value_original = m.wrk_flt_fault_cd,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN wrk_flt m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_fault_code) = RTRIM(m.wrk_flt_fault_cd)
    WHERE d.wkr_mst_fault_code IS NOT NULL
      AND d.wkr_mst_fault_code LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;

    --UPDATE d
    --   SET d.wkr_mst_fault_code = (m.wrk_flt_fault_cd)
    --FROM wkr_mst d
    --INNER JOIN wrk_flt m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_fault_code) = RTRIM(m.wrk_flt_fault_cd)
    --WHERE d.wkr_mst_fault_code IS NOT NULL
    --  AND d.wkr_mst_fault_code LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_fault_code) <> DATALENGTH(RTRIM(m.wrk_flt_fault_cd));

    /* =========================================
    6. Work Request - Work Area
    ========================================= */
    SELECT 
        section_name          = '6. Work Request - Work Area',
        d.site_cd,
        detail_value_original = d.wkr_mst_work_area,
        master_value_original = m.mst_war_work_area,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN mst_war m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_work_area) = RTRIM(m.mst_war_work_area)
    WHERE d.wkr_mst_work_area IS NOT NULL
      AND d.wkr_mst_work_area LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;

    --UPDATE d
    --   SET d.wkr_mst_work_area = (m.mst_war_work_area)
    --FROM wkr_mst d
    --INNER JOIN mst_war m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_work_area) = RTRIM(m.mst_war_work_area)
    --WHERE d.wkr_mst_work_area IS NOT NULL
    --  AND d.wkr_mst_work_area LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_work_area) <> DATALENGTH(RTRIM(m.mst_war_work_area));

    /* =========================================
    7. Work Request - Asset Level
    ========================================= */
    SELECT 
        section_name          = '7. Work Request - Asset Level',
        d.site_cd,
        detail_value_original = d.wkr_mst_assetlocn,
        master_value_original = m.ast_lvl_ast_lvl,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN ast_lvl m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_assetlocn) = RTRIM(m.ast_lvl_ast_lvl)
    WHERE d.wkr_mst_assetlocn IS NOT NULL
      AND d.wkr_mst_assetlocn LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;

    --UPDATE d
    --   SET d.wkr_mst_assetlocn = (m.ast_lvl_ast_lvl)
    --FROM wkr_mst d
    --INNER JOIN ast_lvl m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_assetlocn) = RTRIM(m.ast_lvl_ast_lvl)
    --WHERE d.wkr_mst_assetlocn IS NOT NULL
    --  AND d.wkr_mst_assetlocn LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_assetlocn) <> DATALENGTH(RTRIM(m.ast_lvl_ast_lvl));

    /* =========================================
    8. Work Request - Location
    ========================================= */
    SELECT 
        section_name          = '8. Work Request - Location',
        d.site_cd,
        detail_value_original = d.wkr_mst_location,
        master_value_original = m.ast_loc_ast_loc,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN ast_loc m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_location) = RTRIM(m.ast_loc_ast_loc)
    WHERE d.wkr_mst_location IS NOT NULL
      AND d.wkr_mst_location LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;

    --UPDATE d
    --   SET d.wkr_mst_location = (m.ast_loc_ast_loc)
    --FROM wkr_mst d
    --INNER JOIN ast_loc m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_location) = RTRIM(m.ast_loc_ast_loc)
    --WHERE d.wkr_mst_location IS NOT NULL
    --  AND d.wkr_mst_location LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_location) <> DATALENGTH(RTRIM(m.ast_loc_ast_loc));

    /* =========================================
    9. Work Request - Charge Cost Center
    ========================================= */
    SELECT 
        section_name          = '9. Work Request - Charge Cost Center',
        d.site_cd,
        detail_value_original = d.wkr_mst_chg_costcenter,
        master_value_original = m.costcenter,
        d.mbl_audit_date,
        d.mbl_audit_user
    FROM wkr_mst d
    INNER JOIN cf_cost_center m
        ON d.site_cd = m.site_cd
       AND RTRIM(d.wkr_mst_chg_costcenter) = RTRIM(m.costcenter)
    WHERE d.wkr_mst_chg_costcenter IS NOT NULL
      AND d.wkr_mst_chg_costcenter LIKE '% '
      AND d.mbl_audit_date IS NOT NULL
      AND d.mbl_audit_user IS NOT NULL;

    --UPDATE d
    --   SET d.wkr_mst_chg_costcenter = (m.costcenter)
    --FROM wkr_mst d
    --INNER JOIN cf_cost_center m
    --    ON d.site_cd = m.site_cd
    --   AND RTRIM(d.wkr_mst_chg_costcenter) = RTRIM(m.costcenter)
    --WHERE d.wkr_mst_chg_costcenter IS NOT NULL
    --  AND d.wkr_mst_chg_costcenter LIKE '% '
    --  AND d.mbl_audit_date IS NOT NULL
    --  AND d.mbl_audit_user IS NOT NULL
    --  AND DATALENGTH(d.wkr_mst_chg_costcenter) <> DATALENGTH(RTRIM(m.costcenter));

    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    IF @@TRANCOUNT > 0
        ROLLBACK TRANSACTION;

    SELECT
        ERROR_NUMBER()    AS ErrorNumber,
        ERROR_MESSAGE()   AS ErrorMessage,
        ERROR_LINE()      AS ErrorLine,
        ERROR_PROCEDURE() AS ErrorProcedure;
END CATCH;
GO