这些行通常是第一次进入目标表的方式是,稀疏的列填充了大部分文本数据,其余的列设置为NULL。在随后的遍历中,新数据将填充现有的已知(非null)和未知(NULL)数据。我确定新鲜数据(#pld)确实包含不同的数据。数据似乎没有改变。这是我所拥有的: BEGIN TRANSACTION BEGIN TRY MERGE INTO [metro].listings AS metroList USING #pld as listnew ON metroList.id = listnew.id AND metroList.sid = listnew.sid WHEN MATCHED AND ( metroList.User != listnew.User or metroList.Email != listnew.Email or metroList.LocName != listnew.LocName ) THEN UPDATE SET metroList.User = listnew.User, metroList.Email = listnew.Email, metroList.LocName = listnew.LocName, WHEN NOT MATCHED THEN INSERT ( User, Email, LocName ) VALUES ( listnew.User, listnew.Email, listnew.LocName ); COMMIT TRANSACTION END TRY IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; END CATCH我尝试用将语句的update部分下的!=替换为。结果相同。这必须与将一个可能的(可能是)空值与一个字符串进行比较有关,甚至可能是另一个空值?无论如何,我呼吁所有sql-geeks对此进行解开。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 您也可以将选项与NULLIF()功能一起使用。如果两个表达式不相等,则NULLIF返回第一个表达式。如果表达式相等,则NULLIF返回第一个表达式类型的空值。WHEN MATCHED AND ( NULLIF(ISNULL(metroList.[User],''), listnew.[User]) IS NOT NULL OR NULLIF(ISNULL(metroList.Email, ''), listnew.Email) IS NOT NULL OR NULLIF(ISNULL(metroList.LocName, ''), listnew.LocName) IS NOT NULL )THEN关于sql - SQL Server:MERGE具有意外结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15373214/ (adsbygoogle = window.adsbygoogle || []).push({});
10-09 21:22