select top 10 from tb   同时对这10条更新一个字段:UPdate  tb set 某=某 where????
在同一个存储过程中,对才搜索出来的十条更新怎么写?

解决方案 »

  1.   

    set rowcount 10
    UPdate  tb set 某=某 where????
      

  2.   

    set rowcount 10
    update b set f='x'或者
    update b set f='x' where id in(select top 10 id from tb order by id)
      

  3.   

    UPdate  tb set 某=某 
    where id in 
    (select top 10 id from tb)
      

  4.   

    set rowcount 10
    update...
    set rowcount 0
      

  5.   

    update b set f='x' where id in(select top 10 id from tb order by id)
    接分
      

  6.   

    select top 10 from tb   同时对这10条更新一个字段 要求没有看清楚??? 
     是先搜索出来然后在更新,不是先更新在搜索!谢谢大家捧场
      

  7.   

    set rowcount 10
    update...
    set rowcount 0
    ===============
    这个方法是不对的
    LZ的意思是先把表的前10条抓出来,再从这里面来更新符合条件的行。
    因此不能仅仅Set RowCount = 10
    LZ:
    如果你的表有主键或是唯一键可以唯一标识一行的话,应该很好实现:
    Update t 
    Set ...
    From tb t,(Select Top 10 From tb) t1
    Where t.唯一标识 = t1.唯一标识如果没有的话,情况会比较复杂,今天没时间分析了,明天有空再想。
      

  8.   

    set rowcount 10
    update...
    set rowcount 0
    的方法是正确的。
    通过下面数据可以看出,数据是先经过查询过滤才进行更新的。
    create table t(id int identity(1,1), id2 int)
    insert t select 1
    union all select 2
    union all select 3
    union all select 4
    union all select 5
    union all select 6
    union all select 7set rowcount 3
    update t
    set id2=10000
    where id<7 and 2<id-- 4 rows (3,4,5,6)
    set rowcount 0
    select * from tdrop table t
    /*
    id          id2         
    ----------- ----------- 
    1           1
    2           2
    3           10000
    4           10000
    5           10000
    6           6
    7           7
    */
      

  9.   

    set rowcount 10
    update...
    set rowcount 0
      

  10.   

    dutguoyi(新鲜鱼排)
    --------------------
    set rowcount 10
    update...
    set rowcount 0
    的方法是正确的。
    通过下面数据可以看出,数据是先经过查询过滤才进行更新的。
    create table t(id int identity(1,1), id2 int)
    insert t select 1
    union all select 2
    union all select 3
    union all select 4
    union all select 5
    union all select 6
    union all select 7-----------------------按照LZ的意思,应该是先Select Top 3 From t,然后再Update这三行数据。
    那结果应该是
    /*
    id          id2         
    ----------- ----------- 
    1           1
    2           2
    3           10000
    4           4
    5           5
    6           6
    7           7
    */
    或者其他情况(如果Select Top 3 * From t的结果不是按照id来排序的话,就相当的麻烦了,这个和表的索引及插入数据的顺序有关了,所以要看LZ的实际环境和目的)
      

  11.   

    LZ:
    如果你的表有主键或是唯一键可以唯一标识一行的话,应该很好实现:
    Update t 
    Set ...
    From tb t,(Select Top 10 From tb) t1
    Where t.唯一标识 = t1.唯一标识
    =====================
    还要再加上你所提到的Update的条件