-4

I am using SQL Server 2008 R2. I have a table DESTI

CODE_DESTI   ENTERPRISE 
-----------------------
1            xx
1            yy
12           pp
12           oo
12           ll 

How can I update the duplicate CODE_DESTI with auto increment 1 number after it

CODE_DESTI   ENTERPRISE 
-----------------------
11            xx
12            yy
121           pp
122           oo
123           ll
4

1 回答 1

1

您可以使用 Window 函数执行此操作:

SELECT
    CODE_DESTI + CAST(RANK() AS varchar) OVER (PARTITION BY CODE_DESTI ORDER BY ENTERPRISE) AS CODE_DESTI,
    ENTERPRISE
FROM DESTI
于 2012-12-10T15:31:46.203 回答