AT
1
2
3
4
5
B表
BT MM
1 o
2 u
3 j
4 l
5 k
A表的AT等于B表的BT字段
要求把AT改成MM的内容
结果如下
A表
AT
o
u
j
l
k
10 个解决方案
#1
update A
set AT=B.MM
from a,b
where a.AT=B.BT
#2
update A set AT=B.MM from B where A.AT =B.BT
#3
update a
set a.at = b.mm
from a,b
where a.at = b.bt
#4
update a set a.AT=b.MM
from A表 a,B表 b where a.AT=b.BT
#5
要是类型相同的话就直接
update A set AT=B.MM from A join B on A.AT =B.BT
update A set AT=B.MM from A join B on A.AT =B.BT
#6
update a
set a.AT = b.MM
from A a,B b
where a.AT = b.BT
#7
update a
set at=mm
from a inner join b
on a.at=b.bt
set at=mm
from a inner join b
on a.at=b.bt
#8
update A set AT=B.MM from B where A.AT =B.BT
#9
if db_id('A') is not null
drop table A
go
create table A
(
[AT] char(1) not null
)
if db_id('B') is not null
drop table B
go
create table B
(
[BT] char(1) not null,
MM char(1) not null
)
insert into A
select '1' union
select '2' union
select '3' union
select '4' union
select '5'
go
insert into B
select '1','o' union
select '2','u' union
select '3','j' union
select '4','l' union
select '5','k'
go
update A set a.[AT]=b.MM
from A a
left join B b
on a.[AT]=b.BT
select * from A
drop table A,B
AT
----
o
u
j
l
k
#10
update 表A set AT=MM from 表B where AT=BT
#1
update A
set AT=B.MM
from a,b
where a.AT=B.BT
#2
update A set AT=B.MM from B where A.AT =B.BT
#3
update a
set a.at = b.mm
from a,b
where a.at = b.bt
#4
update a set a.AT=b.MM
from A表 a,B表 b where a.AT=b.BT
#5
要是类型相同的话就直接
update A set AT=B.MM from A join B on A.AT =B.BT
update A set AT=B.MM from A join B on A.AT =B.BT
#6
update a
set a.AT = b.MM
from A a,B b
where a.AT = b.BT
#7
update a
set at=mm
from a inner join b
on a.at=b.bt
set at=mm
from a inner join b
on a.at=b.bt
#8
update A set AT=B.MM from B where A.AT =B.BT
#9
if db_id('A') is not null
drop table A
go
create table A
(
[AT] char(1) not null
)
if db_id('B') is not null
drop table B
go
create table B
(
[BT] char(1) not null,
MM char(1) not null
)
insert into A
select '1' union
select '2' union
select '3' union
select '4' union
select '5'
go
insert into B
select '1','o' union
select '2','u' union
select '3','j' union
select '4','l' union
select '5','k'
go
update A set a.[AT]=b.MM
from A a
left join B b
on a.[AT]=b.BT
select * from A
drop table A,B
AT
----
o
u
j
l
k
#10
update 表A set AT=MM from 表B where AT=BT