To solve your problem as described in your question, consider the following:
DECLARE @NewQNo VARCHAR(20)
DECLARE @OriginalQNo VARCHAR(20)
SET @OriginalQNo = 'res/12-19/001'
SET @NewQNo = RIGHT('00' + CAST(RIGHT(@OriginalQNo, 3) + 1 AS VARCHAR), 3)
SET @NewQNo = LEFT(@OriginalQNo, LEN(@OriginalQNo) - 3) + @NewQNo
PRINT @NewQNo
In order to format the number as a 3-digit one with trailing zeroes, you simply prepend two zeros as a string to the start of the number and then extract the right-most three digits, which will produce in this case 002
.
In order to also include the rest of the question syntax, the second SET
line prepends the starting characters of the question (in this case, res/12-19/
to the completed 3-digit string.
Output:
res/12-19/002