两个表A和B,当A表的字段A1等于B表的字段B1时,同时更新A表的字段A2和B表的字段B2,用一条语句怎么实现,谢谢!(sqlserver2000)

解决方案 »

  1.   

    update a 
    set a.a2=isnull(b.b2,a.a2)
    from a left join b
      on a.a1=b.b1
      

  2.   

    表A ID,数量,金额,日期,一致否
    表B ID,数量,金额,日期,一致否当满足条件 
          A.id=B.id and A.数量=B.数量 and A.金额=B.金额 and A.日期=B.日期
    时,用一条语句同时更新
          A.一致否=1 和B.一致否=1
      

  3.   

    写2条语句,一个update只能写一个表
      

  4.   


    create procedure my_proc
    as
    begin
      update A set A2 = ... from A , B where A.A1 = B.B1
      update B set B2 = ... from B , A where B.A1 = A.B1
    end
    goexec my_proc
      

  5.   

     dawugui提供的是一个实现的方法,能不能用一条语句搞定呢?如果是sqlserver2005或2008呢?
      

  6.   

    一个UPDATE语句只能更新一个表,可以这更新的表中建立触发器以更新另一个表
      

  7.   

    可以这么写:
    update A set A2 = ... from A , B where A.A1 = B.B1;update B set B2 = ... from B , A where B.A1 = A.B1
    注意分号分割