 悬赏园豆:10
                [已解决问题] 
            
                    解决于 2009-09-16 17:09
                悬赏园豆:10
                [已解决问题] 
            
                    解决于 2009-09-16 17:09 
                 
        两个表A和B,要求把B表中的BInfo字段更新到A表中AInfo字段去.
A 表
AID,AInfo
B 表
BID,BInfo
A,B两表通过AID,BID关联.
条件要求更新A表中AInfo为空,但相应的BInfo不为空的字段
创建个Procedure应该就可以解决了吧
create proc ab as
begin
    declare @id int, @binfo char(10) 
declare tc cursor for 
  select a.aid,b.binfo from a,b where a.aid=b.bid
  and a.ainfo is null and b.binfo is not null
open tc
fetch next from tc into @id, @binfo
while @@fetch_status = 0
begin
 update a set a.ainfo=@binfo where a.aid=@id
        
 fetch next from tc into @id, @binfo
end
close tc
deallocate tc
end
update A set SomeCol=0
from B inner join A on A.AID=B.BID and A.AInfo is null and B.BInfo is not null
或
update A set SomeCol=0
from B inner join A on A.AID=B.BID
where A.AInfo is null and B.BInfo is not null