运行此更新语句后
update lol as l
set prodnr = p.prodnr
from prog as p
where (l.ponr in ('1000') and l.abo=p.abo and l.sto=p.sto and l.ponr=p.ponr
and l.prodnr!=p.prodnr)
我希望以下select语句产生0条记录
select *
from lol l, prog p
where (l.ponr in ('1000') and l.abo=p.abo and l.sto=p.sto and l.ponr=p.ponr
and l.prodnr!=p.prodnr)
但不幸的是,情况并非如此...... 为什么?
修改 我几乎疯了......我想,问题是,表条件中有多条记录用于这种情况:l.abo = p.abo和l.sto = p.sto和l.ponr = p.ponr 和l.prodnr!= p.prodnr。在我添加以下附加条件后:
and p.pversion notnull and p.pversion !='0' and p.pversion = l.pversion
所以表达式如下:
update lol as l
set prodnr = p.prodnr
from prog as p
where (l.ponr in ('1000') and l.abo=p.abo and l.sto=p.sto and l.ponr=p.ponr
and l.prodnr!=p.prodnr and p.pversion notnull and p.pversion !='0' and p.pversion = l.pversion)
选择
select *
from lol l, prog p
where (l.ponr in ('1000') and l.abo=p.abo and l.sto=p.sto and l.ponr=p.ponr
and l.prodnr!=p.prodnr and p.pversion notnull and p.pversion !='0' and p.pversion = l.pversion)
产生0条记录。所以我想知道,如果第一次更新真的更新任何东西。也许是第一个创建的记录,它符合条件'(l.ponr in(' 1000')和l.abo = p.abo和l.sto = p.sto和l.ponr = p.ponr 和l.prodnr!= p.prodnr)'