私は何週間もの間、これに対する解決策を探していました。2 つのテーブルをマージする必要がありますが、id(pk) は自動インクリメントされ、同じになることはほとんどないため、信頼できません。ここで私のSPの場合:
BEGIN
MERGE dbo.Publication AS Target
USING (SELECT id, parent_publication_id, name, date_created, last_updated
FROM dbo.ImportPublication
where id = @publicationid
)
AS Source
ON (Target.name = Source.name and Target.parent_publication_id = Source. parent_publication_id)
WHEN MATCHED THEN
UPDATE SET
Target.name = Source.name, Target.parent_publication_id = Source.parent_publication_id, Target.date_created = Source.date_created, Target.last_updated = Source.last_updated
WHEN NOT MATCHED BY TARGET THEN
INSERT (name, parent_publication_id, date_created, last_updated )
VALUES ( Source.name, Source.parent_publication_id, Source.date_created, Source.last_updated);
DECLARE @pubId INT = SCOPE_IDENTITY()
if(@pubId != null or @pubId !='')
begin
UPDATE dbo.ImportFixedSize
SET publication_id = @pubId
where publication_id = @publicationId
end
else
begin
set @pubId = ( select Id from Publication where name = ( select name from ImportPublication where id = @publicationid))
UPDATE dbo.ImportFixedSize
SET publication_id = @pubId
where publication_id = @publicationId
end
見出しにエラーが表示されます。原因は何ですか?事実として、2 つの行が同じ名前であり、publication_group_id ではないことを知っています。