我有两个表nol_art和#tmpIzm我想用表#tmpIzm中的值更新nol_art,如果它不为null,否则值保持不变
我写的代码,但有一些错误,所以它不起作用:
update nol_art
set
CENA_IZM=if(xd.IZM IS NULL,' ',xd.IZM)
from
#tmpIzm xd
join nol_art a on a.ART_ID=xd.ID_ART
where
a.ART_ID=xd.ID_ART
答案 0 :(得分:3)
试试这个:
update nol_art
set
CENA_IZM=coalesce(xd.IZM, CENA_IZM)
from
#tmpIzm xd
join nol_art a on a.ART_ID=xd.ID_ART
where
a.ART_ID=xd.ID_ART
答案 1 :(得分:1)
我在DB2中做到了
UPDATE
document
SET
department =
(SELECT departmentId
FROM
department
WHERE
document.base_child = document.base_child AND
document.folder_child = document.folder_child)
WHERE
EXISTS
( SELECT * FROM department
WHERE department.base_child = department.base_child
AND department.folder_child = department.folder_child);
希望能帮助