表 a
  字段:ptype, uname ,unint ,barcorde 
表 b
   字段:type, uname ,fullname,barcorde 2两表靠b.type=a.ptype  进行关联。职何让  把表b中的表barcorde值更新到 a表中.barcorde字段中update peUnit  set a.BarCode=b.barcode FROM   peUnit a,ptype  b where a.PtypeId=b.typeId AND a.nUnit=1update peUnit set a.BarCode=b.barcode FROM  T_Jxc_PtypeUnit a JOIN ptype  b on a.PtypeId=b.typeId where  a.nUnit=1都不行,提示
消息 4104,级别 16,状态 1,第 1 行
无法绑定由多个部分组成的标识符 "a.BarCode"。本人SQL基础差,请高手帮忙写一下正确的SQL更新语句。

解决方案 »

  1.   

    update a -- 这里写别名
    set a.c = b.c
    from t1 a,t2 b
    where 
      

  2.   

    UPDATE  peUnit
    SET     BarCode = ( SELECT TOP 1
                                barcode
                        FROM    ptype
                        WHERE   peUnit.PtypeId = ptype.typeId
                      )
    WHERE   nUnit = 1
      

  3.   

    --set 后不用指定表别名
    update peUnit  set BarCode=b.barcode FROM   peUnit a,ptype  b where a.PtypeId=b.typeId AND a.nUnit=1