diff --git a/rds_mysql/stored_procedure/crm_history.sql b/rds_mysql/stored_procedure/crm_history.sql index 3247da51..caeb09c0 100644 --- a/rds_mysql/stored_procedure/crm_history.sql +++ b/rds_mysql/stored_procedure/crm_history.sql @@ -10,7 +10,7 @@ BEGIN EXECUTE new_history_save_stmt; -- ②-1 Salesforce側で更新されたデータを検出用一時テーブルの作成 - SET @make_history_tmp_create = 'CREATE TEMPORARY TABLE make_history_tmp SELECT id, MIN(@@target_column) AS min_start_datetime, MAX(start_datetime) AS max_start_datetime FROM @@target_table WHERE end_datetime = "9999-12-31 00:00:00" GROUP BY id'; + SET @make_history_tmp_create = 'CREATE TEMPORARY TABLE make_history_tmp SELECT id, MIN(@@target_column) AS min_start_datetime, MAX(start_datetime) AS max_start_datetime FROM @@target_table WHERE end_datetime = "9999-12-31 00:00:00" GROUP BY id HAVING count(id) = 2'; SET @make_history_tmp_create = REPLACE(@make_history_tmp_create, "@@target_table", target_table); SET @make_history_tmp_create = REPLACE(@make_history_tmp_create, "@@target_column", target_column); PREPARE make_history_tmp_create_stmt from @make_history_tmp_create;