[转帖]update 更新表中多条记录。从另一个表中调用记录。
我的应用:
创建主表:
update tbA set a3=a3+B.b3 from (select b1,b3 FROM tbB) B where a1 in ( B.b1)----------------------------------------------use northwindGOcreate table tem_1( names char(10),number int )declare @num intset @num = 1while @num <10begin insert into tem_1 values ('chen' ,@num)set @num=@num+1endselect * from tem_1create table tem_2( names char(10),number int )declare @num intset @num = 10while @num <20begin insert into tem_2 values ('MAckson' ,@num)set @num=@num+1endselect * from tem_2update tem_1 set names = B.names from tem_1 as A,tem_2 as B where A.number <10 Drop tem_1Drop tem_2 Go