fxh    FNumber           fxh     FNumber
 1     2312220102010001    1      23122201020100011   
 2     2312220102010001    2      23122201020100012   
 3     2312220102010002    3      23122201020100021   
 4     2312220102010003    4      23122201020100031   
 5     2312220102010003    5      23122201020100032   
 6     2312220102010004    6      23122201020100041   
 7     2312220102010005    7      23122201020100051   
 8     2312220102010005    8      23122201020100052   
 9     2312220102010005    9      23122201020100053   
 10    2312220102010005    10     23122201020100054   
 ...    ...                      
数据很多

解决方案 »

  1.   

    update 
       tb
    set
        FNumber= FNumber+ltrim(ltrim(row_number() over(partition by FNumber order by getdate()))
      

  2.   

    update tb set cast(FNumber as varchar) + cast((select count(1) from tb where FNumber = t.FNumber and fxh < t.fxh) + 1 as varchar) from tb t
      

  3.   

    create table tb(fxh int,FNumber nvarchar(20))
    insert into tb select 1,'2312220102010001'
    insert into tb select 2,'2312220102010001'
    insert into tb select 3,'2312220102010002'
    insert into tb select 4,'2312220102010003'
    insert into tb select 5,'2312220102010003'
    insert into tb select 6,'2312220102010004'
    insert into tb select 7,'2312220102010005'
    insert into tb select 8,'2312220102010005'
    insert into tb select 9,'2312220102010005'
    insert into tb select 10,'2312220102010005'
    go
    select fxh,fnumber+ltrim(rn) fnumber from(
    select *,row_number()over(partition by fnumber order by (select 1))rn from tb
    )t
    /*
    fxh         fnumber
    ----------- --------------------------------------------
    1           23122201020100011
    2           23122201020100012
    3           23122201020100021
    4           23122201020100031
    5           23122201020100032
    6           23122201020100041
    7           23122201020100051
    8           23122201020100052
    9           23122201020100053
    10          23122201020100054(10 行受影响)*/
    go
    drop table tb
      

  4.   

    or:
    create table tb(fxh int,FNumber nvarchar(20))
    insert into tb select 1,'2312220102010001'
    insert into tb select 2,'2312220102010001'
    insert into tb select 3,'2312220102010002'
    insert into tb select 4,'2312220102010003'
    insert into tb select 5,'2312220102010003'
    insert into tb select 6,'2312220102010004'
    insert into tb select 7,'2312220102010005'
    insert into tb select 8,'2312220102010005'
    insert into tb select 9,'2312220102010005'
    insert into tb select 10,'2312220102010005'
    go
    select fxh,fnumber+ltrim(rn) fnumber from(
    select *,row_number()over(partition by fnumber order by fxh)rn from tb
    )t
    /*
    fxh         fnumber
    ----------- --------------------------------------------
    1           23122201020100011
    2           23122201020100012
    3           23122201020100021
    4           23122201020100031
    5           23122201020100032
    6           23122201020100041
    7           23122201020100051
    8           23122201020100052
    9           23122201020100053
    10          23122201020100054(10 行受影响)*/
    go
    drop table tb
      

  5.   

    如要更新原表,则:
    create table tb(fxh int,FNumber nvarchar(20))
    insert into tb select 1,'2312220102010001'
    insert into tb select 2,'2312220102010001'
    insert into tb select 3,'2312220102010002'
    insert into tb select 4,'2312220102010003'
    insert into tb select 5,'2312220102010003'
    insert into tb select 6,'2312220102010004'
    insert into tb select 7,'2312220102010005'
    insert into tb select 8,'2312220102010005'
    insert into tb select 9,'2312220102010005'
    insert into tb select 10,'2312220102010005'
    go
    update a set FNumber=Fnumber+ltrim(b.rn) from tb a inner join(
    select fxh,row_number()over(partition by fnumber order by fxh)rn from tb
    )b on a.fxh=b.fxh
    select * from tb
    /*
    fxh         fnumber
    ----------- --------------------------------------------
    1           23122201020100011
    2           23122201020100012
    3           23122201020100021
    4           23122201020100031
    5           23122201020100032
    6           23122201020100041
    7           23122201020100051
    8           23122201020100052
    9           23122201020100053
    10          23122201020100054(10 行受影响)*/
    go
    drop table tb
      

  6.   

    update tb set FNumber = cast(FNumber as varchar) + cast((select count(1) from tb where FNumber = t.FNumber and fxh < t.fxh) + 1 as varchar) from tb t
      

  7.   

    CREATE TABLE TEST
    (
        fxh     INT
      , FNumber CHAR(16)
    )INSERT INTO TEST
    SELECT 1,  '2312220102010001'
    UNION ALL
    SELECT 2,  '2312220102010001'
    UNION ALL
    SELECT 3,  '2312220102010002'
    UNION ALL
    SELECT 4,  '2312220102010003'
    UNION ALL
    SELECT 5,  '2312220102010003'
    UNION ALL
    SELECT 6,  '2312220102010004'
    UNION ALL
    SELECT 7,  '2312220102010005'
    UNION ALL
    SELECT 8,  '2312220102010005'
    UNION ALL
    SELECT 9,  '2312220102010005'
    UNION ALL
    SELECT 10, '2312220102010005'SELECT fxh
         , FNumber + CONVERT(VARCHAR(3), ROW_NUMBER() OVER (PARTITION BY FNumber ORDER BY fxh)) AS FNumber
    FROM   TESTDROP TABLE TEST