T-SQL string manipulation question

I created a stored procedure that returns, for example,

  00001 FROM 40900100001
  00002 from 40900100002
  19999 from 40900119999

I want to increase this value to

  00001 --> 0002
  00002 --> 00003
  19999 --> 20000

How can i do this?

+3
source share
1 answer

How about something like

DECLARE @Val VARCHAR(20)

SELECT @Val = '00011'

SELECT  REPLICATE('0', LEN(@Val) - LEN(@Val + 1)) + CAST((@Val + 1) AS VARCHAR(20))
+3
source

Source: https://habr.com/ru/post/1779551/


All Articles