日期:2014-05-18 浏览次数:20775 次
update tbl1 set type=a.type from tbl2 a where a.uid=tbl1.uid
------解决方案--------------------
create table #t1(id int, xtype char(1))
insert into #t1 select 1,NULL
union all select 2,NULL
union all select 2,NULL
union all select 3,NULL
union all select 4,NULL
create table #t2(id int, xtype char(1))
insert into #t2 select 1,'a'
union all select 2,'b'
union all select 3,'c'
union all select 4,'d'
update #t1 set xtype=(select xtype from #t2 where #t1.id=#t2.id)
select * from #t1
-----------------------------------
id xtype
----------- -----
1 a
2 b
2 b
3 c
4 d
(5 行受影响)