有表A 的字段值为 A
A
A
B
B
B
C
C
如何实现 ,用简单的办法
A_1
A_2
A_3
B_1
B_2
B_3
C_1
C_2

解决方案 »

  1.   

    declare @t table(a varchar(5))
    insert @t
    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' 
    declare @i int,@var varchar(5)
    set @i=0
    update @t
        set  @i=case a when @var then @i+1 else 1 end,
             @var=case a when @var then @var else a end,
             a=a+'_'+cast(@i as varchar)select * from @t结果就是楼主要的