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

update子查询
有两张表A,B,共同的字段包括(a,b,c)   A中主码字段名为KeyA,   B中主码字段为KeyB
现在想用B中的数据更新A
update   A   set   (a,b,c)=(select   a,b,c   from   B   where   KeyB= 'fdsa ')
where   KeyA= 'fdas '

在查询分析器里面提示出错,应该怎么写呢,求助中。。。。。。  


------解决方案--------------------
update a
set a.a = b.a,a.b= b.b,a.c = b.c
from a
join b on a.keya = b.keyb
where a.keya = 'fdas '
------解决方案--------------------
楼上正解.
------解决方案--------------------
declare @a,@b,@c varchar(50)
select @a=a,@b=b,@c=c from B where KeyB= 'fdsa '
update A set a=@a,b=@b,c=@c where KeyA= 'fdas '