首页 新闻 会员 周边 捐助

求助SQL更新语句啊..急啊..

0
悬赏园豆: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不为空的字段

用心创造精彩每一天的主页 用心创造精彩每一天 | 初学一级 | 园豆:175
提问于:2009-09-16 16:33
< >
分享
最佳答案
0

创建个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

收获园豆:5
Gnie | 菜鸟二级 |园豆:468 | 2009-09-16 16:46
其他回答(1)
0
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
收获园豆:5
邀月 | 园豆:25475 (高人七级) | 2009-09-16 16:40
谢了.
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册