declare @A table
(
a1 int,
a2 nvarchar(30)
)
declare @B table
(
b1 int,
b2 nvarchar(30)
)
insert into @A(a1)
select 1 union all
select 2 union all
select 2 union all
select 3 union all
select 2
insert into @B(b1,b2)
select 1,'#' union all
select 2,'¥' union all
select 3,'%'
------------
--核心就这句
update A
set A.a2=B.b2
from @A A
inner join @B B on(A.a1=B.b1)
-------
--查询一下
select * from @A
--
解决:
a1 a2
---------------
1 #
2 ¥
2 ¥
3 %
2 ¥
select A.a1,A.a2=B.b2 from A inner join B on A.id=B.id