Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL question about manipulation on strings

I have created stored procedure which 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 that?

like image 997
AEMLoviji Avatar asked Dec 05 '25 15:12

AEMLoviji


1 Answers

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))
like image 176
Adriaan Stander Avatar answered Dec 08 '25 09:12

Adriaan Stander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!