これは私のために働く
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;