sql怎么把修改后表的内容更新到老表里啊 我想把红圈里的这个值更新到另一个表里

img

sql怎么把修改后表的内容更新到老表里啊 我想把红圈里的这个值更新到已经存在的另一个表里

sqlserver中的多表关联更新,可以参考官方文档

选取其中一个例子

UPDATE dbo.Table2   
SET dbo.Table2.ColB = dbo.Table1.ColB  
FROM dbo.Table2   
    INNER JOIN dbo.Table1   
    ON (dbo.Table2.ColA = dbo.Table1.ColA)

这个例子几乎和你的要求一模一样了,只需要把表名和字段名替换一下就行了


另外,关于多表关联更新,各个数据库虽然都有所区别,但其实有个通用的方法,可以用下面这个sql得到验证

create table test_20220315_a(id int,val VARCHAR(10));
insert into test_20220315_a values (1,null );
insert into test_20220315_a values (2,null );

create table test_20220315_b(id int,val VARCHAR(10));
insert into test_20220315_b values(1,'a');
insert into test_20220315_b values(2,'b');

update  test_20220315_a  
set val=(select val from test_20220315_b  where test_20220315_a.id=test_20220315_b.id)
where exists (select 1 from test_20220315_b  where test_20220315_a.id=test_20220315_b.id)

update HRrs set HRrs .vIDNo=hr_hi_person.vIDNo  from A,B where A.字段=B.字段 and A.字段N=B.字段N