diff --git a/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql b/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql index e2d8d77a..32301d14 100644 --- a/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql +++ b/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql @@ -2,6 +2,11 @@ CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` (target_table VARCHAR(100), target_column VARCHAR(100)) BEGIN +-- 変数宣言 +DECLARE distribution_schema VARCHAR(100); +DECLARE target_column_value VARCHAR(100); +DECLARE TempTableId VARCHAR(18); + -- エラー処理 DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -12,13 +17,8 @@ DECLARE EXIT HANDLER FOR SQLEXCEPTION SET MYSQL_ERRNO = @error_state, MESSAGE_TEXT = @error_msg; END; --- 変数宣言 -DECLARE distribution_schema VARCHAR(100); -DECLARE target_column_value VARCHAR(100); -DECLARE TempTableId VARCHAR(18); - -- カーサー設定 -SELECT Id, target_column INTO @ControlTable FROM internal02.crm_Product_Metrics_vod__c; +SELECT Id, target_column INTO @ControlTable FROM internal02.target_table; -- ループ ControlTableLoop: WHILE EXISTS (SELECT * FROM ControlTable) @@ -29,14 +29,13 @@ ControlTableLoop: WHILE EXISTS (SELECT * FROM ControlTable) SET distribution_schema = get_distribution_to_schema(target_table, target_column, target_column_value); -- UPSERT文 - INSERT INTO distribution_schema.crm_Product_Metrics_vod__c (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__c, Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) + INSERT INTO distribution_schema.target_table (Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__c, Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date) SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__c, Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, delete_flg, ins_user, ins_date, upd_user, upd_date - FROM internal02.crm_Product_Metrics_vod__c AS internaltb + FROM internal02.target_table AS internaltb WHERE Id = TempTableId - ON DUPLICATE KEY UPDATE (IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, MayEdit, IsLocked, LastViewedDate, LastReferencedDate, Account_vod__c, Awareness__c, Selling_Stage__c, Formulary_Status__c, Movement__c, Products_vod__c, Segment__c, X12_mo_trx_chg__c, Speaker_Skills__c, Investigator_Readiness__c, Engagements__c, Mobile_ID_vod__c, External_ID_vod__c, MSJ_Patient__c, Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c, MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c, EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c, EMDS_Influence__c, EMDS_Main_Driver__c, EMDS_Priority__c, EMDS_Willingness__c, MSJ_KTL_Type__c, MSJ_KTL_Tier__c, MSJ_Publications__c, MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c, MSJ_Associations__c, MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c, start_datetime, end_datetime, file_name, file_row_cnt, upd_user, upd_date) - IsDeleted = internaltb.IsDeleted, Name = internaltb.Name, CreatedDate = internaltb.CreatedDate, CreatedById = internaltb.CreatedById, LastModifiedDate = internaltb.LastModifiedDate, LastModifiedById = internaltb.LastModifiedById, SystemModstamp = internaltb.SystemModstamp, MayEdit = internaltb.MayEdit, IsLocked = internaltb.IsLocked, LastViewedDate = internaltb.LastViewedDate, LastReferencedDate = internaltb.LastReferencedDate, Account_vod__c = internaltb.Account_vod__c, Awareness__c = internaltb.Awareness__c, Selling_Stage__c = internaltb.Selling_Stage__c, Formulary_Status__c = internaltb.Formulary_Status__c, Movement__c = internaltb.Movement__c, Products_vod__c = internaltb.Products_vod__c, Segment__c = internaltb.Segment__c, X12_mo_trx_chg__c = internaltb.X12_mo_trx_chg__c, Speaker_Skills__c = internaltb.Speaker_Skills__c, Investigator_Readiness__c = internaltb.Investigator_Readiness__c, Engagements__c = internaltb.Engagements__c, Mobile_ID_vod__c = internaltb.Mobile_ID_vod__c, External_ID_vod__c = internaltb.External_ID_vod__c, MSJ_Patient__c = internaltb.MSJ_Patient__c, Detail_Group_vod__c = internaltb.Detail_Group_vod__c, MSJ_EB_1st_Line_Liver_Meta__c = internaltb.MSJ_EB_1st_Line_Liver_Meta__c, MSJ_EB_1st_Line_Multi_Meta__c = internaltb.MSJ_EB_1st_Line_Multi_Meta__c, MSJ_EB_2nd_Line_Mono__c = internaltb.MSJ_EB_2nd_Line_Mono__c, MSJ_EB_2nd_Line_Combination__c = internaltb.MSJ_EB_2nd_Line_Combination__c, MSJ_EB_3rd_Line_Mono__c = internaltb.MSJ_EB_3rd_Line_Mono__c, MSJ_EB_3rd_Line_Combination__c = internaltb.MSJ_EB_3rd_Line_Combination__c, EMDS_Ability__c = internaltb.EMDS_Ability__c, EMDS_Brand_Loyalty__c = internaltb.EMDS_Brand_Loyalty__c, EMDS_Decision_Maker__c = internaltb.EMDS_Decision_Maker__c, EMDS_Early_Tech_Adopter__c = internaltb.EMDS_Early_Tech_Adopter__c, EMDS_Influence__c = internaltb.EMDS_Influence__c, EMDS_Main_Driver__c = internaltb.EMDS_Main_Driver__c, EMDS_Priority__c = internaltb.EMDS_Priority__c, EMDS_Willingness__c = internaltb.EMDS_Willingness__c, MSJ_KTL_Type__c = internaltb.MSJ_KTL_Type__c, MSJ_KTL_Tier__c = internaltb.MSJ_KTL_Tier__c, MSJ_Publications__c = internaltb.MSJ_Publications__c, MSJ_Clinical_Trials__c = internaltb.MSJ_Clinical_Trials__c, MSJ_Speaker_for_Medical_Events__c = internaltb.MSJ_Speaker_for_Medical_Events__c, MSJ_Advisor_to_Medical_Affairs__c = internaltb.MSJ_Advisor_to_Medical_Affairs__c, MSJ_Guidelines_Treatment_Standards__c = internaltb.MSJ_Guidelines_Treatment_Standards__c, MSJ_Therapeutic_Area_Expertise__c = internaltb.MSJ_Therapeutic_Area_Expertise__c, MSJ_MAP_GAP__c = internaltb.MSJ_MAP_GAP__c, MSJ_Associations__c = internaltb.MSJ_Associations__c, MSJ_Tier_Score__c = internaltb.MSJ_Tier_Score__c, medaca_parent_msj_product_classification__c = internaltb.medaca_parent_msj_product_classification__c, start_datetime = internaltb.start_datetime, end_datetime = internaltb.end_datetime, file_name = internaltb.file_name, file_row_cnt = internaltb.file_row_cnt, upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP() + ON DUPLICATE KEY UPDATE IsDeleted = IsDeleted = VALUES(internaltb.IsDeleted), Name = VALUES(internaltb.Name), CreatedDate = VALUES(internaltb.CreatedDate), CreatedById = VALUES(internaltb.CreatedById), LastModifiedDate = VALUES(internaltb.LastModifiedDate), LastModifiedById = VALUES(internaltb.LastModifiedById), SystemModstamp = VALUES(internaltb.SystemModstamp), MayEdit = VALUES(internaltb.MayEdit), IsLocked = VALUES(internaltb.IsLocked), LastViewedDate = VALUES(internaltb.LastViewedDate), LastReferencedDate = VALUES(internaltb.LastReferencedDate), Account_vod__c = VALUES(internaltb.Account_vod__c), Awareness__c = VALUES(internaltb.Awareness__c), Selling_Stage__c = VALUES(internaltb.Selling_Stage__c), Formulary_Status__c = VALUES(internaltb.Formulary_Status__c), Movement__c = VALUES(internaltb.Movement__c), Products_vod__c = VALUES(internaltb.Products_vod__c), Segment__c = VALUES(internaltb.Segment__c), X12_mo_trx_chg__c = VALUES(internaltb.X12_mo_trx_chg__c), Speaker_Skills__c = VALUES(internaltb.Speaker_Skills__c), Investigator_Readiness__c = VALUES(internaltb.Investigator_Readiness__c), Engagements__c = VALUES(internaltb.Engagements__c), Mobile_ID_vod__c = VALUES(internaltb.Mobile_ID_vod__c), External_ID_vod__c = VALUES(internaltb.External_ID_vod__c), MSJ_Patient__c = VALUES(internaltb.MSJ_Patient__c), Detail_Group_vod__c = VALUES(internaltb.Detail_Group_vod__c), MSJ_EB_1st_Line_Liver_Meta__c = VALUES(internaltb.MSJ_EB_1st_Line_Liver_Meta__c), MSJ_EB_1st_Line_Multi_Meta__c = VALUES(internaltb.MSJ_EB_1st_Line_Multi_Meta__c), MSJ_EB_2nd_Line_Mono__c = VALUES(internaltb.MSJ_EB_2nd_Line_Mono__c), MSJ_EB_2nd_Line_Combination__c = VALUES(internaltb.MSJ_EB_2nd_Line_Combination__c), MSJ_EB_3rd_Line_Mono__c = VALUES(internaltb.MSJ_EB_3rd_Line_Mono__c), MSJ_EB_3rd_Line_Combination__c = VALUES(internaltb.MSJ_EB_3rd_Line_Combination__c), EMDS_Ability__c = VALUES(internaltb.EMDS_Ability__c), EMDS_Brand_Loyalty__c = VALUES(internaltb.EMDS_Brand_Loyalty__c), EMDS_Decision_Maker__c = VALUES(internaltb.EMDS_Decision_Maker__c), EMDS_Early_Tech_Adopter__c = VALUES(internaltb.EMDS_Early_Tech_Adopter__c), EMDS_Influence__c = VALUES(internaltb.EMDS_Influence__c), EMDS_Main_Driver__c = VALUES(internaltb.EMDS_Main_Driver__c), EMDS_Priority__c = VALUES(internaltb.EMDS_Priority__c), EMDS_Willingness__c = VALUES(internaltb.EMDS_Willingness__c), MSJ_KTL_Type__c = VALUES(internaltb.MSJ_KTL_Type__c), MSJ_KTL_Tier__c = VALUES(internaltb.MSJ_KTL_Tier__c), MSJ_Publications__c = VALUES(internaltb.MSJ_Publications__c), MSJ_Clinical_Trials__c = VALUES(internaltb.MSJ_Clinical_Trials__c), MSJ_Speaker_for_Medical_Events__c = VALUES(internaltb.MSJ_Speaker_for_Medical_Events__c), MSJ_Advisor_to_Medical_Affairs__c = VALUES(internaltb.MSJ_Advisor_to_Medical_Affairs__c), MSJ_Guidelines_Treatment_Standards__c = VALUES(internaltb.MSJ_Guidelines_Treatment_Standards__c), MSJ_Therapeutic_Area_Expertise__c = VALUES(internaltb.MSJ_Therapeutic_Area_Expertise__c), MSJ_MAP_GAP__c = VALUES(internaltb.MSJ_MAP_GAP__c), MSJ_Associations__c = VALUES(internaltb.MSJ_Associations__c), MSJ_Tier_Score__c = VALUES(internaltb.MSJ_Tier_Score__c), medaca_parent_msj_product_classification__c = VALUES(internaltb.medaca_parent_msj_product_classification__c), start_datetime = VALUES(internaltb.start_datetime), end_datetime = VALUES(internaltb.end_datetime), file_name = VALUES(internaltb.file_name), file_row_cnt = VALUES(internaltb.file_row_cnt), upd_user = CURRENT_USER(), upd_date = CURRENT_TIMESTAMP() ; -- UPSERT終了後ControlTableから削除