我想创建一个合并,它将比较两个表并将不匹配的值插入到另一个第三个表或表变量中,如下所示:
MERGE Assets AS target
USING (@id, @name)FROM Sales AS source (id, name) ON (target.id = SOURCE.id)
WHEN MATCHED THEN
UPDATE SET target.Status = @status, target.DateModified = SYSUTCDATETIME()
WHEN NOT MATCHED THEN
INSERT INTO @tableVar (id, name, status, dateModified)
VALUES (@id, @name, @status, SYSUTCDATETIME())
可以这样做还是有其他方法?