繁体   English   中英

结果不一致-更新与选择

[英]Inconsistent Result - Update versus Select

我运行下面的语句,并不能明白为什么update影响0行同时select与同一连接和where返回1行。 它们都是Varchar类型,并且crmnumberAC较大,因此应该能够从AccountNumber中获取字符串。 思考?

begin transaction
update c
set c.crmnumberAC = a.AccountNumber
--select a.name, a.AccountNumber, c.fullname, c.crmnumberAC 
from Contact as c
right join Account as a
    on c.PFH_Mapping_Ac_ContacId = a.AccountId
WHERE (a.AccountNumber IS NOT NULL AND c.crmnumberAC IS NULL) 
    OR a.AccountNumber != c.crmnumberAC
rollback transaction

这是当我取消注释select并仅将其运行到where时的结果集;

在此处输入图片说明

如您所见,您的SELECT不会从表Contact(您尝试UPDATE的表)中返回任何内容。

SELECT仅由于您具有正确的SELECT返回一行,但是在表Contact中,没有满足where条件的行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM