SQL 合并输出同一个 table

SQL Merge and output in the same table

我正在合并 2 个表,我希望如果更新单元格,该字段将被标记为 "updated" 我的代码:

 MERGE [ITWORKS].[dbo].[Testine2] te
    USING [ITWORKS].[dbo].[Testinus] bo
    ON te.itemid = bo.itemid
    AND te.itemname <> bo.itemname
    WHEN MATCHED THEN
      UPDATE
      SET te.itemname = bo.itemname
     OUTPUT
        $action
       into  [ITWORKS].[dbo].[Testine2] (busena);
    SELECT * FROM [ITWORKS].[dbo].[Testine2];

我得到的结果:

Itemid  Itemname Busena 
100001  TEST      NULL 
NULL    Null      UPADTE

我想要的结果:

Itemid  Itemname Busena
100001  TEST      UPDATE

I want that if the cell is update the field would be marked as "updated"

没有理由使用输出。只需在更新中设置列值即可。

MERGE [ITWORKS].[dbo].[Testine2] te
    USING [ITWORKS].[dbo].[Testinus] bo
    ON te.itemid = bo.itemid
    AND te.itemname <> bo.itemname
    WHEN MATCHED THEN
      UPDATE
      SET te.itemname = bo.itemname,
          te.Busena = 'UPDATE';

SELECT * FROM [ITWORKS].[dbo].[Testine2];