SQL Server在合并时追加列

时间:2018-06-18 09:34:42

标签: sql sql-server

我要求附加列数据,同时我需要检查主键是否已存在。所以我用以下来检查是否存在主键,然后分别更新或创建。但我想将数据添加到Meeting列(如果已存在)。有人可以建议解决方案吗?

MERGE
  INTO tblStatus WITH (HOLDLOCK) AS target
  USING
    (SELECT '2018-06-18' AS sdate, 15813 AS Meeting) AS source (sdate, Meeting)
  ON
    (target.sdate = source.sdate)
  WHEN MATCHED THEN
    UPDATE
      [tblStatus] SET Meeting = 12000 
  WHEN NOT MATCHED THEN
    INSERT                                                 
      (sdate, Meeting) VALUES ('2018-06-18', 15813);

0 个答案:

没有答案