MsSql Merge不起作用

时间:2015-10-07 12:34:43

标签: sql sql-server stored-procedures sql-server-2005 merge

我正在尝试进行合并但由于某种原因我收到错误。

我正在做的是:我插入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.*;

0 个答案:

没有答案