数据库结构如下
a      b       c
13     女     娇娇
46     男     泱泱
25     男     扬扬
现在想将a列数据全部重新生成,变成每行递增+1
a      b       c
13     女     娇娇
14     男     泱泱
15     男     扬扬
这样的格式,请问如何弄?数据库a列是char型

解决方案 »

  1.   

    declare @t table(a varchar(4),b varchar(4),c varchar(4))
    insert into @t select '13','女','娇娇'
    insert into @t select '46','男','泱泱'
    insert into @t select '25','男','扬扬'declare @a varchar(4)
    update @t
    set
        a =isnull(@a,a),
        @a=isnull(@a,a)+1
        
    select * from @t/*
    a    b    c    
    ---- ---- ---- 
    14   女    娇娇
    15   男    泱泱
    16   男    扬扬
    */
      

  2.   

    --有点问题,更正一下:
    declare @t table(a varchar(4),b varchar(4),c varchar(4))
    insert into @t select '13','女','娇娇'
    insert into @t select '46','男','泱泱'
    insert into @t select '25','男','扬扬'declare @a varchar(4)
    update @t
    set
        @a=isnull(@a,a)+1,
        a =isnull(@a,a)-1
        
    select * from @t
    /*
    a    b    c    
    ---- ---- ---- 
    13   女    娇娇
    14   男    泱泱
    15   男    扬扬
    */