两个不同的数据库模糊比较后,向其中一个表另一列填数据(在线等)
两个不同的数据库中(两个表中其中有一列数据基本相同),向其中一个表另一列填数据,
table1 table2
X Y X
a1 a1
a2 a2
b1 b1
b2 b2
c1 c1-Sa
c2 c2-Za
table1和table2比较后,给Y列填数据
X Y
a1 a1
a2 a2
b1 b1
b2 b2
c1 c1
c2 c2
用UPDATE 语句怎么写?谢谢!!!
[解决办法]
update tabel1 a
set a.y=left(b.x,len(a.x))
from tabel2 b
where a.x=left(b.x,len(a.x))
[解决办法]
要修改下,
update a
set a.y=left(b.x,len(a.x))
from tabel1 a, tabel2 b
where a.x=left(b.x,len(a.x))
[解决办法]
create table table1(x varchar(10),y varchar(10))
insert table1(x)
select 'a1 '
union select 'a2 '
union select 'b1 '
union select 'b2 '
union select 'c1 '
union select 'c2 '
create table table2(x varchar(10))
insert table2
select 'a1 '
union select 'a2 '
union select 'b1 '
union select 'b2 '
union select 'c1-Sa '
union select 'c2-Za '
select * from table1
select * from table2
update a
set a.y=left(b.x,len(a.x))
from table1 a , table2 b
where a.x=left(b.x,len(a.x))
select * from table1
select * from table2
drop table table1,table2