1

在我的数据库中,我的列包含 40 条相同的记录,名为jee_phy_2. 我想将数字增加jee_phy_21 jee_phy_40。谁能告诉我

DECLARE @q_id  NVARCHAR(50),@txt bigint,@final nvarchar(50)
begin 

SET @q_id='JEE_PHY_1' 


UPDATE oems_question7 SET q_id=@q_id+1 WHERE id between 1 and 40

end
4

2 回答 2

1

这是你要找的吗?

UPDATE x
SET x.q_id = 'jee_phy_' + cast(x.newNum as nvarchar(10))
FROM (
      SELECT q_id, ROW_NUMBER() OVER (ORDER BY [q_id]) AS newNum
      FROM oems_question7
      ) x

小提琴演示

于 2013-08-19T12:20:58.567 回答
0

尝试这个

DECLARE @q_id  NVARCHAR(50)
begin 

SET @q_id='JEE_PHY_1' 

UPDATE oems_question7  SET q_id = SUBSTRING (@q_id ,0,CHARINDEX('_', @q_id,5) + 1 ) + ' ' + CONVERT(NVARCHAR,CONVERT(INT, SUBSTRING ( @q_id ,CHARINDEX('_', @q_id,5) + 1, LEN(@q_id) )) +1)
WHERE id between 1 and 40

end
于 2013-08-19T12:05:17.860 回答