declare  @i int,@field1  varchar(20)
set  @i=0
set  @field1=''
update  表  set field2=@i,@i=(case when  @field1=field1  then @i+1  else 1   end),@field1=field1

解决方案 »

  1.   

    declare  @i int,@field1  varchar(20)
    set  @i=0
    set  @field1=''
    update  表  set field2=@i,@i=(case when  @field1=field1  then @i+1  else 1   end),@field1=field1
    select  *  from 表 -----檢查一下結果就是了
      

  2.   

    select *  from 表
    where 1=1
    order by field1,field2
      

  3.   

    Softlee81307(孔腎)  真的么?
    查询和变量赋值不能同时进行,更新和赋值能同时进行么?
      

  4.   

    可不可以用SQL语句直接写阿?没有权限写过程啊。
      

  5.   

    可不可以用SQL语句直接写阿?没有权限写过程啊。
      

  6.   

    Update可以同时更新和变量赋值,Select不可以同时查询与变量赋值
      

  7.   

    如果表中有关键字id,可以这样写select field1, ( select count(*) from 表 where id <= a.id and field1 = a.field1 ) as field2 from 表 a
      

  8.   

    create table test000(id int identity(1,1),col nvarchar(10))
    insert into test000 select 'A' union all select 'A' union all select 'A' union all select 'A' union all 
    select 'B' union all select 'B' union all select 'B' union all 
    select 'C' union all select 'C' union all select 'C' union all select 'C'select col, ( select count(*) from test000 where id <= a.id and col = a.col ) as field2 
    from test000 a
    drop table test000
      

  9.   

    可以现实是web server 不会给我这么多的权限,关键字id 也没有。也许只能在 dataset 里处理了。
    是这样吗?
      

  10.   

    我用了一下 xluzhong(打麻将一缺三,咋办?)  的方法,现在可以把问题简化到
    field1          field2
    --------------------
    A               1
    A               2 
    A               3
    A               4
    B               5
    B               6
    C               7
    C               8
    C               9只要有一个不断累加的字段就可以了,套用xluzhong(打麻将一缺三,咋办?)  的方法就可以实现了,请问各位有没有好办法? 谢谢
      

  11.   

    用临时表,加不断累加的id
    create table test000(col nvarchar(10))
    insert into test000 select 'A' union all select 'A' union all select 'A' union all select 'A' union all 
    select 'B' union all select 'B' union all select 'B' union all 
    select 'C' union all select 'C' union all select 'C' union all select 'C'select id=identity(int,1,1),* into #t from test000 order by colselect col,( select count(*) from #t where id <= a.id and col = a.col ) as field2 
    from #t a
    drop table test000
      

  12.   

    没有建立零时表的权限,只有 SELECT 的权限。 太难了,可恶的WEB SERVER