我想将不匹配的输出插入到两个表中。当我尝试插入存储过程的输出时,它会将所有更新的值也添加到新表中,而不仅仅是“表”中没有匹配的值
尝试了好几种方法都没用
ALTER PROCEDURE [dbo].[identify]
AS
BEGIN
SET NOCOUNT ON;
MERGE INTO [test].[dbo].[warehouse] AS dim
USING [test].[dbo].[staging] AS stg
ON dim.[first_name] = stg.first_name
WHEN MATCHED THEN
UPDATE SET
dim.[first_name] = stg.first_name,
dim.last_name = stg.last_name,
dim.created_date = stg.created_date,
dim.modified_date = stg.modified_date,
dim.gender = stg.gender
WHEN NOT MATCHED THEN
INSERT(first_name, last_name, created_date, modified_date, gender)
VALUES(first_name, last_name,created_date, modified_date,gender)
OUTPUT Inserted.first_name, Inserted.last_name INTO test (first_name,last_name);
END
...
OUTPUT Inserted.first_name, Inserted.last_name, Deleted.first_name INTO #test (new_first_name, new_last_name, old_first_name);
INSERT INTO test (first_name, last_name)
SELECT *
FROM #test new_first_name, new_last_name
WHERE new_first_name IS NOT NULL AND old_first_name IS NULL;
DROP TABLE #test;