I want to create a merge that will compare two tables and insert not matched values into another third table or table variable something like this:
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())
Can this be done or are there other methods?