首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么替换

2012-05-01 
如何替换t1Usernameabcd...t2UsernameNUNaXbYcZdM...把T1 中的username 替换为t2 中的nun[解决办法]SQL co

如何替换
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 allselect 'b' union allselect 'c' union allselect '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 allselect 'b','Y' union allselect 'c','Z' union allselect 'd','M'update t1set [Username]=a.[NUN] from t2 a where t1.Username=a.Usernameselect * from t1/*UsernameXYZM*/ 

热点排行