日期:2014-05-18 浏览次数:21164 次
--> 测试数据:[tb2]
if object_id('[tb2]') is not null drop table [tb2]
create table [tb2]([name] varchar(4),[address] varchar(8),[address1] varchar(8))
insert [tb2]
select '张三','北京',NULL union all
select '李四','河北',NULL union all
select '王五','河南',NULL union all
select '张三','朝阳区',NULL union all
select '张三','阳光大街',NULL
SELECT * FROM [tb2]
update t1
set [address1]=t1.[address]
from [tb2] t1,[tb2] t2
where t1.[address] =t2.[address]
-----或者
update [tb2] set [address1]=[address]
/*
name address address1
---- -------- --------
张三 北京 北京
李四 河北 河北
王五 河南 河南
张三 朝阳区 朝阳区
张三 阳光大街 阳光大街
(5 行受影响)
*/
------解决方案--------------------
update table_a set table_a=table_b实现不了?
字段和表名一样? 改下字段名看: update table_a set field_a=field_b
------解决方案--------------------