From 2ae3b889f07442ffff24f341b6e02101634b964c Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Thu, 19 Oct 2023 10:24:40 +0900 Subject: [PATCH] =?UTF-8?q?Product=5FMetrics=5Fvod=5F=5Fc.sql=E3=81=AE?= =?UTF-8?q?=E3=83=97=E3=83=83=E3=82=B7=E3=83=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rm_distribution_Product_Metrics_vod__c.sql | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql 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 new file mode 100644 index 00000000..81baf252 --- /dev/null +++ b/rds_mysql/stored_procedure/internal02/crm_distribution_Product_Metrics_vod__c.sql @@ -0,0 +1,39 @@ +CREATE PROCEDURE `crm_distribution_Product_Metrics_vod__c` (target_table VARCHAR(100), target_column VARCHAR(100)) +BEGIN + +-- 変数宣言 +DECLARE distribution_schema VARCHAR(100); +DECLARE target_table VARCHAR(100) DEFAULT 'crm_Product_Metrics_vod__c'; +DECLARE target_column VARCHAR(100); +DECLARE target_column_value VARCHAR(100); +DECLARE TempTableId VARCHAR(18); + +-- カーサー設定 +DECLARE Product_Metrics_vod__c_CURSOR CURSOR FOR +SELECT * FROM internal02.crm_Product_Metrics_vod__c INTO ControlTable; + +-- ループ +ControlTableLoop: WHILE EXISTs (SELECT * FROM ControlTable) +DO + +-- スキーマ取得 +SELECT Id FROM ControlTable ORDER BY Id ASC LIMIT 1 INTO TempTableId; +SELECT medaca_parent_msj_product_classification__c FROM internal02.crm_Product_Metrics_vod__c WHERE Id=TempTableId INTO target_column_value; +SET distribution_schema = get_distribution_to_schema(target_table, target_column, target_column_value); + +-- 例外処理、ループ抜け +IF (distribution_schema != src02m OR distribution_schema != src02c) THEN +LEAVE ControlTableLoop; +END IF; + +-- 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`) +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 WHERE Id = TempTableId; + + +-- UPSERT終了後ControlTableから削除 +DELETE FROM ControlTable WHERE Id = TempTableId; +END WHILE; + +END