这个要怎么赋值?
有两个表:
表A:
A_BH A_Name
1
2
3
表B
B_BH B_Name
1 陈楚生
2 吉杰
3 郭德纲
怎么才能把表A的A_Name赋值为表B的B_Name(条件是A_BH = B_BH)
------解决方案--------------------update a set a_name=b.b_name from a inner join b on a.a_bh=b.b_bh
------解决方案--------------------UPDATE b SET B_Name = a.A_Name
FROM tableB as b INNER JOIN tableA as a on a.A_BH = b.B_BH
------解决方案--------------------update 表A set A_Name = B.B_Name
from 表A as A
inner join 表B as B ON A.A_BH = B.B_BH
------解决方案--------------------抱歉,看错题意,其他二位朋友的回复是正确的.
------解决方案--------------------n^n
------解决方案--------------------update A set A_Name=B_Name from A inner join B on A_BH=B_BH
------解决方案-------------------- declare @A table(A_BH int,A_Name nvarchar(10))
declare @B table(B_BH int,B_Name nvarchar(10))
insert into @A select 1, ' ' union all select 2, ' ' union all select 3, ' '
insert into @B select 1,N '陈楚生 ' union all select 2,N '吉杰 ' union all select 3,N '郭德纲 '
update @A set A_Name = B_Name from @A ,@B where A_BH = B_BH
select * from @A
结果:
A_BH A_Name
----------- ----------
1 陈楚生
2 吉杰
3 郭德纲