A表:
Acol1 Acol2
1 null
2 null
3 null
1 null
B表:
Bcol1 Bclo2
1 a
2 b
3 c
要得到结果:
A表:
Acol1 Acol2
1 a
2 b
3 c
1 a怎么写update ?
Acol1 Acol2
1 null
2 null
3 null
1 null
B表:
Bcol1 Bclo2
1 a
2 b
3 c
要得到结果:
A表:
Acol1 Acol2
1 a
2 b
3 c
1 a怎么写update ?
from a inner join b on a.Acol1=b.Bcol1
insert into a
select 1,null
union all
select 2,null
union all
select 3,null
union all
select 1,nullcreate table b (Bcol1 int,Bcol2 char(2))
insert into b
select 1,'a'
union all
select 2,'b'
union all
select 3,'c'UPDATE a SET A.ACOL2=B.BCOl2
FROM A,B
WHERE A.ACOL1=B.BCOL1select * from a
update A set Acol2 = ( select Bcol2 from B where A.Acol1 = B.Bcol1 )
declare @t table(acol1 int ,acol2 varchar(2))
declare @t1 table(bcol1 int ,bcol2 varchar(2))insert into @t
select 1, null union all
select 2, null union all
select 3, null union all
select 1, nullinsert into @t1
select 1, 'a' union
select 2, 'b' union
select 3, 'c' update @t
set acol2 = b.bcol2
from @t a , @t1 b
where a.acol1 = b.bcol1
update A set Acol2=B.Bcol2 from A,B where A.Acol1=B.col1