以下语句是否有语法错误?
update a set a.funitid=b.fbaseunit
from T_BD_MaterialInventory a,T_BD_Material b 
where  b.fid=a.fmaterialid and b.fbaseunit <> a.funitid 

解决方案 »

  1.   

    语法错误update T_BD_MaterialInventory a 
       set a.funitid=(select b.fbaseunit 
                        from T_BD_Material b 
                       where  b.fid=a.fmaterialid 
                         and b.fbaseunit <> a.funitid )
      

  2.   

    直接update是不支持超过1个表关联的 只能通过子查询关联更新
      

  3.   

     a.fmaterialid 和 b.fid一对多 还是一对一 如果一对一 1L应该可以 如果一对多 那可以加个条件 update T_BD_MaterialInventory a 
    set a.funitid=(select fbaseunit 
                        from T_BD_Material b 
                       where a.fmaterialid = b.fid
                         and a.funitid <> b.fbaseunit and rownum = 1)
      

  4.   

    确实是一对多的情况,那这个SQL脚本的意思是不是说:将T_BD_MaterialInventory 表中的 funitid 全部改成select子句中查出来的那个值?
      

  5.   

    仔细看看啊,我这个改过了哎呀,最后加了个rownum=1啊,你自己试试
      

  6.   


    加个rownum = 1 就在查询出在对应表T_BD_Material中多行fbaseunit中的第一行数据如果子查询返回多行数据 就会报错 单行查询返回多个值  必须只能返回一行
      

  7.   

    update T_BD_MaterialInventory a 
       set a.funitid=(select b.fbaseunit 
                        from T_BD_Material b 
                       where  b.fid=a.fmaterialid 
                         and b.fbaseunit <> a.funitid 
                         and rownum = 1)这个应该是可以的
      

  8.   

    update T_BD_MaterialInventory a 
       set a.funitid=(select distinct b.fbaseunit 
                        from T_BD_Material b 
                       where  b.fid=a.fmaterialid 
                         and b.fbaseunit <> a.funitid 
                        )试试。