我想更新tmp_final表的dept_code_9字段,根据tmp_huiduishuju表的dept_code_9字段值,但是系统报错:命令未正确结束,求解:
update tmp_final
set tmp_final.dept_code_9=tmp_huiduishuju.dept_code_9
where tmp_final.dept_code_8=tmp_huiduishuju.dept_code_8
update tmp_final
set tmp_final.dept_code_9=tmp_huiduishuju.dept_code_9
where tmp_final.dept_code_8=tmp_huiduishuju.dept_code_8
update tmp_final
set tmp_final.dept_code_9=(select tmp_huiduishuju.dept_code_9
from tmp_huiduishuju
where tmp_final.dept_code_8=tmp_huiduishuju.dept_code_8)
你都没有检索tmp_huiduishuju这个表对象,肯定会报错的。
set tmp_final.dept_code_9=(select tmp_huiduishuju.dept_code_9
from tmp_huiduishuju
where tmp_final.dept_code_8=tmp_huiduishuju.dept_code_8) where exits
(
select 1
from tmp_huiduishuju
where tmp_final.dept_code_8=tmp_huiduishuju.dept_code_8
);
一般的跟新是这种写法;
多条时为:
update tmp_final
set (tmp_final.dept_code_9,col2)=(select tmp_huiduishuju.dept_code_9,tmp_huiduishuju.col2
from tmp_huiduishuju
where tmp_final.dept_code_8=tmp_huiduishuju.dept_code_8) where exits
(
select 1
from tmp_huiduishuju
where tmp_final.dept_code_8=tmp_huiduishuju.dept_code_8
);