在 SQL Server 上执行以下操作时,我希望 NULL 用值 88888888 更新,但它会插入一个新行。有人可以告诉我我做错了什么吗?
USE tempdb;
CREATE TABLE TableA (ColA CHAR(8), ColB CHAR(8))
CREATE TABLE TableB (ColA CHAR(8), ColB CHAR(8))
INSERT INTO TableA VALUES ( 'XXXXXXXX', NULL )
INSERT INTO TableA VALUES ( 'XXXXXXXX', '88888888')
MERGE INTO TableB AS T
USING TableA AS S
ON T.ColA = S.ColA and T.ColB = S.ColB
WHEN MATCHED
THEN
UPDATE
SET T.ColA = S.ColA, T.ColB = S.ColB
WHEN NOT MATCHED BY TARGET
THEN
INSERT (ColA, ColB) VALUES (S.ColA, S.ColB);
SELECT * FROM TableA
SELECT * FROM TableB
DROP TABLE TableA
DROP TABLE TableB
非常感谢!最好的问候,史蒂夫