当前位置:编程学习 > C#/ASP.NET >>

两个表怎么逐步更新?

我现在有两张表A B 他们有同一个字段plan 我知道直接更新的语句但是现在遇到个问题,plan这个字段在表A中对应多个行 我现在通过B 更新A字段的unit_code SQL语句提示返回多个查询 怎么用for循环实现逐步更新啊 --------------------编程问答-------------------- 不知道你要干嘛,能否描述的详细一些 --------------------编程问答-------------------- 描述不清,举个例子吧 --------------------编程问答-------------------- update tacacfx1 a set a.unit_code=(select b.unit_code ,b.prod_plan_no from tpmmmss01 b, tacacfx1 a where a.sub_plan_no=b.prod_plan_no )  我要干得其实就是这个 但是我tacacfx1表中  sub_plan_no的值不唯一 就是有多行有同一个sub值 所以老报错所返回多行信息 --------------------编程问答-------------------- 加个条件就好 rownum=1,SQL的就用TOP 1  --------------------编程问答-------------------- 还是不行 他提示值过多 --------------------编程问答-------------------- 使用多表更新就行了。sql2008测试通过。
update tacacfx1 
set tacacfx1.unit_code = tpmmmss01.unit_code
from tacacfx1 join tpmmmss01 on tacacfx1.sub_plan_no = tpmmmss01.prod_plan_no --------------------编程问答--------------------
update tacacfx1 a set a.unit_code=(select b.unit_code from tpmmmss01 b left join tacacfx1 a where a.sub_plan_no=b.prod_plan_no ) 
--------------------编程问答-------------------- 我试一下 我这里是plsql --------------------编程问答-------------------- 用游标或者多个update这个更好。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,