有2个表 tb1 有cid,pid tb2也有cid,pid。 现在tb1里数据完整的,tb2只cid有数据,要把tb1里的pid导到tb2里面的cid where tb1.cid=tb2.cid 并且tb2里的cid不是完整的
怎么用存储过程实现

解决方案 »

  1.   

    update tb2
    set cid = tb1.pid
    from tb1
    where tb1.cid = tb2.cid
      

  2.   

    update tb2 set pid=b.pid from tb2 a,tb1 b where a.cid=b.cid
      

  3.   

    update tb2
    set pid=tb1.pid
    from tb1 ,tb2
    where tb1.cid=tb2.cidgo
    insert tb2(cid,pid)
    select cid,pid
    from tb1
    where not exists(select 1 from tb2 where cid=tb1.cid )
      

  4.   

    --一段為存在更新tb2.pid
    --二段為不存時新增到tb2
      

  5.   

    select tb1.pid from tb1,tb2 where tb1.cid=tb2.cid  查出来的是一列啊  要赋值过去 最好要有循环就好呢