这对我有用
MERGE Table1 AS tgt
USING
(
SELECT
TOP 1
*
FROM
Table2,
(
SELECT
itmid
FROM
Table3
WHERE
id = @id
) as a
WHERE
id = @id
) AS src
ON ( tgt.id = src.id )
WHEN MATCHED THEN
UPDATE SET qty = qty + @qty
WHEN NOT MATCHED THEN
INSERT itmid
VALUES itmid;
但是当我这样改变时,它不起作用,最后显示错误select
MERGE Table1 AS tgt
USING
(
SELECT
TOP 1
*
FROM
Table2
WHERE
id = @id
) AS src
ON ( tgt.id = src.id )
WHEN MATCHED THEN
UPDATE SET qty = qty + @qty
WHEN NOT MATCHED THEN
INSERT itmid
SELECT itmid FROM Table3 WHERE id = @id;