1

是否可以将 varchar 列的值设置为字符串和结果集迭代的串联。

例如:

update TB_USER set LOGIN_NAME = 'BOB'+index where LOGIN_NAME = 'BOB'

结果如下:

登录名

BOB0

BOB1

BOB2

4

1 回答 1

5
update T
SET LOGIN_NAME = LOGIN_NAME + CAST(rn AS varchar(10))
FROM
   (SELECT
       LOGIN_NAME,
       ROW_NUMBER() OVER (ORDER BY something /*or (SELECT 1)/*) as rn
    FROM
       TB_USER
    WHERE
       LOGIN_NAME = 'Bob'
    ) T
于 2012-10-30T14:42:36.927 回答