当前位置: 代码迷 >> Sql Server >> 怎么替换
  详细解决方案

怎么替换

热度:27   发布时间:2016-04-27 13:05:57.0
如何替换
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*/
  相关解决方案