有表A 有字段branch_no,,item_no,min_qty,max_qty,display_flag。只有item_no,min_qty,允许空。branch_no必须为00,min_qty,max_qty,display_flag有默认值。表B里有与表A只有相同字段item_no,如何通过表B里的item_no更新表A里的数据,每次更新不是全部更新,只是表A里没有表B里的这个字段数据。

解决方案 »

  1.   

    update TableA
    SET 
        A.需要更新字段 = B.数据字段
    FROM TableA A, TableB B
    WHERE A.item_no = B.item_no AND  A.需要更新字段 is null
      

  2.   


    --你想更新的内容是什么???
    update A
    set ...
    where not exists(select 1
    from B where B.item_no=A.item_no);
      

  3.   

    只是我说的那几个字段,只要B里有的item_no,A就有,就是说B里有多少条数据,A里酒有多少。
      

  4.   

    不好意思我说错了,是表A里需要增加B里的item_no,增加数据条件只要A里没有的,
      

  5.   

    通过B里的item_no增加B里的数据条数。使A与B有同样的数据行数。
      

  6.   


    insert into 表A([字段列表])
    select [字段列表]
    from 表B b
    left join 表A a
    on b.item_no=a.item_no
    where a.item_no is null
      

  7.   


    insert into 表A(字段列表)
    select 字段列表
    from 表B a
    left join 表A b
    on b.item_no=a.item_no
    where b.item_no is null
      

  8.   

    insert into 表A([字段列表])
    select  字段列表 from b
    except 
    select  字段列表 from a
      

  9.   

    --orinsert into 表A(字段列表)
    select 字段列表
    from 表B a where not exists(select 1 from a where  b.item_no=a.item_no)