更新查询中跳过行
我创建了一个更新查询,以使用 Bestel 表中的数据更新 Partij 表中的行。此查询中缺少一件事,希望有人可以帮助我:)
update partij
set Inkprijs1 = (
select bestel.inkoopprijs
from bestel
where partij.levcod= bestel.levcod
and partij.scancode = bestel.scancode
and bestel.devisie = 'HARDWA')
,inkprijs2 = (
select bestel.prijs
from bestel
where partij.levcod= bestel.levcod
and partij.scancode = bestel.scancode
and bestel.devisie = 'HARDWA')
,PRIJSGRP_1 = (
select bestel.PRIJSGRP_1
from bestel
where partij.levcod= bestel.levcod
and partij.scancode = bestel.scancode
and bestel.devisie = 'HARDWA')
,PRIJSGRP_2 = (
select bestel.PRIJSGRP_2
from bestel
where partij.levcod= bestel.levcod
and partij.scancode = bestel.scancode
and bestel.devisie = 'HARDWA')
where devisie = 'TESTHW'
;
当 Partij 更新函数不存在于表 Bestel 中时,我想跳过它们。当 Partij 表(带有 devsie TESTHW)中存在没有匹配值的行时,根本不应该更新。
希望有人可以帮助我!提前致谢
I've created an update query to update lines in the Partij table with data from the Bestel table. There's one thing missing in this query and hopefully someone can help me :)
update partij
set Inkprijs1 = (
select bestel.inkoopprijs
from bestel
where partij.levcod= bestel.levcod
and partij.scancode = bestel.scancode
and bestel.devisie = 'HARDWA')
,inkprijs2 = (
select bestel.prijs
from bestel
where partij.levcod= bestel.levcod
and partij.scancode = bestel.scancode
and bestel.devisie = 'HARDWA')
,PRIJSGRP_1 = (
select bestel.PRIJSGRP_1
from bestel
where partij.levcod= bestel.levcod
and partij.scancode = bestel.scancode
and bestel.devisie = 'HARDWA')
,PRIJSGRP_2 = (
select bestel.PRIJSGRP_2
from bestel
where partij.levcod= bestel.levcod
and partij.scancode = bestel.scancode
and bestel.devisie = 'HARDWA')
where devisie = 'TESTHW'
;
I want to skip lines for the Partij update function when they don't excist in the table Bestel. When there are lines in the Partij tabel (with devisie TESTHW) without matching values the shouldn't get updatet at all.
Hopefully someone can help me out! Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一:去掉标量子查询:
如果
bestel
中存在相应记录,上面的代码只会触及party
。接下来,您可能想要抑制幂等更新:
最后,您应该引用丑陋的全大写列名(最好避免它们,它们只会造成伤害):
First: get rid of the scalar subqueries:
The above will only touch
party
if corresponding records inbestel
exist.Next, you may want to supprress idempotent updates:
Finally, you should quote the ugly ALLCAPS column names (better avoid them, they do only harm):