update 表 
set TopGoodsLineID=OldLineID where TopGoodsLineID=499
order by ID 

解决方案 »

  1.   

    update t set oldlineid=(select top 1 id from t a where a.oldlineid=t.topgoodslineid)
      

  2.   

    update tb set TopGoodsLineID=a.ID from (select ID from tb where OldLineID=499)a 
    where TopGoodsLineID=a.ID AND TopGoodsLineID = 499
      

  3.   

    上面錯了,應該這樣update tb 
    set TopGoodsLineID=a.ID 
    from (select ID,OldLineID from tb where OldLineID=499)a 
    where TopGoodsLineID=a.OldLineID AND TopGoodsLineID = 499
      

  4.   

    update 表 set TopGoodsLineID = (select id from 表 where 表。OldLineID = '499') WHERE 表.TopGoodLineID = '499'
      

  5.   

    update tablename set tolgoodslinid=t2.id
    from tablename t1,tablename t2
    where t1.topgoodslineid=t2.oldlineid
      

  6.   

    楼主,难道hdhai9451的解答不可以吗?那请把你的要求讲清楚吧!不会存在什么商业机密或军事机密吧?
      

  7.   

    下面的语句居然说:
    服务器: 消息 8154,级别 16,状态 1,行 6
    表 'process_mission_child' 不明确。update process_mission_child 
    set topgoodslinid = t2.id
    from 
    process_mission_child t1,process_mission_child t2
    where 
    t1.topgoodslineid=t2.oldlineid
      

  8.   

    原始:
    ID, TopGoodsLineID, OldLineID
    525,     0, 515
    526, 515, null
    527, 515, null
    528, 515, null
    529,     0, 519
    530, 519, null
    531, 519, null
    532, 519, null
    目标:
    ID, TopGoodsLineID, OldLineID
    525,     0, 515
    526, 525, null
    527, 525, null
    528, 525, null
    529,     0, 519
    530, 529, null
    531, 529, null
    532, 529, null
      

  9.   

    hahai9451是可以的,数字不对你自己改成自己表里对应的撒。
      

  10.   

    把hahai9451的稍改一下:可以了.update process_mission_child 
    set TopGoodsLineID=a.ID 
    from (select ID,OldLineID from process_mission_child where OldLineID is not null)a 
    where TopGoodsLineID=a.OldLineID and process_mission_child.OldLineID is null
      

  11.   

    你到底说说hahai9451可不可以?
      

  12.   

    谢谢了.
     
    xinbeckham:你和hahai9451是不是好朋友啊?这么急?:)
      

  13.   

    update table_name set TopGoodsLineID=ID  from table where TopGoodsLineID=OldLineID 记得用group by 分开做
      

  14.   

    hahai9451:这个也不行,如果有很多的话就不行了,这只是我的理解,呵呵
      

  15.   

    没有类,只是hahai9451和我想的是一样的,我以为有问题,所以要你讲正不正确呀。