我正在嘗試使用同一個表中的另一個欄位更新我表中的一個欄位,但是當我運行下面的更新時出現錯誤
update f1
set f1.usu_cgcstr = f2.cgccpf
from E095for as f1
join E095for as f2
on f1.codfor = f2.codfor
where f1.usu_intot = 'N'
錯誤:
- 00000 - “SQL 命令未正確結束”
那么我該如何進行此更新?
uj5u.com熱心網友回復:
錯誤的語法;使用merge:
merge into f1
using e095for f2
on (f1.codfor = f2.codfor)
when matched then update set f1.usu_cgcstr = f2.cgccpf
where f1.usu_intot = 'N';
或者,如果您想要update:
update e095for f1 set
f1.usu_intot = (select f2.cgccpf
from e095for f2
where f2.codfor = f1.codfor
)
where f1.usu_intot = 'N'
and exists (select null from e095for c
where c.codfor = f1.codfor
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/370195.html
上一篇:如何聯接兩個表中具有相同列名但行值不同的兩個SELECT查詢
下一篇:加載資料時出現完整性約束錯誤
