私の SQL Anywhere 12.0.1 データベースには 2 つのテーブルがあります。
CREATE TABLE "ListDetails" (
ListDetailId UNIQUEIDENTIFIER NOT NULL PRIMARY KEY,
ListId UNIQUEIDENTIFIER NOT NULL,
CountryId VARCHAR(3) NULL REFERENCES "Countries" ( CountryId ) DEFAULT 'USA',
LocaleCode VARCHAR(3) NULL REFERENCES "Locales" ( LocaleCode ),
Plate VARCHAR(50) NULL,
HashedPlate UNIQUEIDENTIFIER NULL,
AlarmClassId INT NULL REFERENCES "AlarmClasses" ( AlarmClassId ),
BeginDate DATETIME NULL,
EndDate DATETIME NULL,
ListPriorityId INT NULL REFERENCES "ListPriorities" ( ListPriorityId ),
VehicleTypeId INT NULL REFERENCES "VehicleTypes" ( VehicleTypeId ),
PlateClassId INT NULL REFERENCES "PlateClasses" ( PlateClassId ),
MakeId INT NULL REFERENCES "VehicleBrands" ( VehicleBrandId ),
ModelId INT NULL REFERENCES "VehicleModels" ( VehicleModelId ),
"Year" INT NULL,
ColorId INT NULL REFERENCES "VehicleColors" ( VehicleColorId ),
Notes VARCHAR(8000) NULL,
OfficerNotes VARCHAR(8000) NULL,
IsNewRow BIT NOT NULL DEFAULT '1',
CreatedDate DATETIME NOT NULL DEFAULT NOW(),
i_active SMALLINT NOT NULL DEFAULT 1,
ModifyDate DATETIME NULL,
Subscriber UNIQUEIDENTIFIER NULL,
FromToVersion BIGINT NOT NULL,
FromVersion BIGINT,
InstanceId UNIQUEIDENTIFIER NOT NULL UNIQUE
);
と:
CREATE GLOBAL TEMPORARY TABLE "ListDetailsLoad" (
ListDetailId UNIQUEIDENTIFIER NOT NULL,
ListId UNIQUEIDENTIFIER NOT NULL,
CountryId VARCHAR(3) NULL,
LocaleCode VARCHAR(3) NULL,
Plate VARCHAR(50) NULL,
HashedPlate UNIQUEIDENTIFIER NULL,
AlarmClassId INT NULL,
BeginDate DATETIME NULL,
EndDate DATETIME NULL,
ListPriorityId INT NULL,
VehicleTypeId INT NULL,
PlateClassId INT NULL,
MakeId INT NULL,
ModelId INT NULL,
"Year" INT NULL,
ColorId INT NULL,
Notes VARCHAR(8000) NULL,
OfficerNotes VARCHAR(8000) NULL,
Subscriber UNIQUEIDENTIFIER NULL,
InstanceId UNIQUEIDENTIFIER NOT NULL
) NOT TRANSACTIONAL;
私のプログラム (C# で作成) は、ListDetailsLoad テーブルへの一括コピーを実行してから、ストアド プロシージャを実行します。ストアド プロシージャの仕事は、データを ListDetails テーブルに移動することです。ストアド プロシージャは次のとおりです。
MERGE INTO "ListDetails" AS dst
USING "ListDetailsLoad" AS src
ON dst.ListDetailId = src.ListDetailId
WHEN MATCHED THEN UPDATE
SET ListDetailId = src.ListDetailId,
ListId = src.ListId,
CountryId = src.CountryId,
LocaleCode = src.LocalCode,
Plate = src.Plate,
HashedPlate = src.HashedPlate,
AlarmClassId = src.AlarmClassId,
BeginDate = src.BeginDate,
EndDate = src.EndDate,
ListPriorityId = src.ListPriorityId,
VehicleTypeId = src.VehicleType,
PlateClassId = src.PlateClassId,
MakeId = src.MakeId,
ModelId = src.ModelId,
"Year" = src."Year",
ColorId = src.ColorId,
Notes = src.Notes,
OfficerNotes = src.OfficerNotes,
ModifyDate = NOW(),
FromToVersion = dbVersion.NEXTVAL,
FromVersion = NULL,
Subscriber = src.Subscriber,
InstanceId = src.InstanceId
WHEN NOT MATCHED THEN INSERT
( ListDetailId, ListId, CountryId, LocaleCode, Plate, HashedPlate,
AlarmClassId, BeginDate, EndDate, ListPriorityId, VehicleTypeId, PlateClassId,
MakeId, ModelId, "Year", ColorId, Notes, OfficerNotes,
ModifyDate, FromToVersion, Subscriber, FromVersion, InstanceId )
VALUES
( src.ListDetailId, src.ListId, src.CountryId, src.LocaleCode, src.Plate, src.HashedPlate,
src.AlarmClassId, src.BeginDate, src.EndDate, src.ListPriorityId, src.VehicleTypeId, src.PlateClassId,
src.MakeId, src.ModelId, src."Year", src.ColorId, src.Notes, src.OfficerNotes,
NOW(), dbVersion.NEXTVAL, NULL, src.Subscriber, src.InstanceId );
TRUNCATE TABLE "ListDetailsLoad";
END;
これはうまくコンパイルされます。問題は、実行すると次のエラーメッセージが表示されることです。
Could not execute statement. Column "ListDetailId" found in more than one table or it is used more than once in the SELECT list -- it needs a correlation name.
MERGE ステートメントを修正するにはどうすればよいですか?