[英]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.