我正在尝试进行合并但由于某种原因我收到错误。
我正在做的是:我插入productname
不为空的所有记录,并且在临时表中没有标记为double。
循环访问临时表以插入/更新真实表[Products]
MERGE INTO [Products] AS T
USING SingleProducts AS S
ON (T.SoftwareID = S.[@ProductCode] AND T.PriceType = S.[@PriceType])
WHEN NOT MATCHED BY TARGET
THEN INSERT (SoftwareID, IsActive, [Image], ProductNameNL, ProductNameFR, DescriptionNL, DescriptionFR, UnitPrice, PriceType, CreationDate, LastUpdatedDate)
VALUES (S.[@ProductCode], 0, 'no-image.png', S.[@ProductNameNL], S.[@ProductNameFR], S.[@DescriptionNL], S.[@DescriptionFR],
S.[@UnitPrice], S.[@PriceType], S.[@CreationDate], GETDATE())
WHEN MATCHED
THEN UPDATE SET
T.[SoftwareID] = S.[@ProductCode],
T.[ProductNameNL] = S.[@ProductNameNL],
T.[ProductNameFR] = S.[@ProductNameFR],
T.[DescriptionNL] = S.[@DescriptionNL],
T.[DescriptionFR] = S.[@DescriptionFR],
T.[UnitPrice] = S.[@UnitPrice],
T.[PriceType] = S.[@PriceType]
WHEN NOT MATCHED BY SOURCE
THEN DELETE
OUTPUT $action, inserted.*, deleted.*;