有表CUSTMST,ORDERTBL
现在我要把ORDERTBL的CUSTNM,ADRESS字段数据更新成从CUSTMST搜索出来的CUSTNM,ADRESS数据。
这个SQL语句该怎么写?

解决方案 »

  1.   

    update o
      set o.custnm=c.custmst,
          o.adress=c.adress
    from ordertbl o
     join custmst c
       on o.id=c.id
      

  2.   

    update a
    set a.custmst = isnull(b.cutmst,a.custmst),a.adress = isnull(b.adress,a.adress)
    from ORDERTBL a left join custmst b 
    on a.xxxx = b.xxx
      

  3.   


    update o
      set o.custnm=c.custmst,
          o.adress=c.adress
    from ordertbl o
     join custmst c
       on o.CUSTCD=c.CUSTCD