在同一数据库中,表1 :T1,表2:T2,现想选择表2最后一条记录的ids字段插入到表一的code 字段 ,条件是:表1的code 字段为NULL时 插入,因为表1是从表,所以为NULL 的code 字段可能为多个,举例来说,表1中最后三条记录的code 字段为NULL,就要向这三个记录插入 同样的ids

解决方案 »

  1.   

    update t1 set t1.code=(select top 1  ids from t2 order by ids desc) where t1.code is null
    你试试,大概是这样的吧
    也不知道你最后一条记录以什么为标准,所以排序是按IDS降序排
      

  2.   

    update t1 set t1.code=(select top 1  ids from t2 order by ids desc) where t1.code is null 
      

  3.   

    ids 是升序排列的,如果表1中最后三条记录的code 字段都为NULL,要向这三个记录插入 同样的ids,要怎么写?