日期:2014-05-18  浏览次数:20630 次

如何替换
t1
Username
a
b
c
d
...

t2
Username NUN
a X
b Y
c Z
d M
...

把T1 中的username 替换为t2 中的nun

------解决方案--------------------
SQL code

--> 测试数据:[t1]
if object_id('[t1]') is not null drop table [t1]
create table [t1]([Username] varchar(1))
insert [t1]
select 'a' union all
select 'b' union all
select 'c' union all
select 'd'
--> 测试数据:[t2]
if object_id('[t2]') is not null drop table [t2]
create table [t2]([Username] varchar(1),[NUN] varchar(1))
insert [t2]
select 'a','X' union all
select 'b','Y' union all
select 'c','Z' union all
select 'd','M'
update t1
set [Username]=a.[NUN] from t2 a where t1.Username=a.Username
select * from t1
/*
Username
X
Y
Z
M
*/