Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My Group I'd values are 1) 123A5 2) 2345B6 3) 897698D8 add 1 to above Strings in Sql server

I need result like
123A6
2345B7
897698D9

What I have tried:

Convert(varchar,substring)+convert(varchar,(convert(int,substring)+1
Posted
Updated 15-Nov-22 18:23pm

1 solution

Okay, this is a 3 part problem to: "get the number at the end of the string and increment it by one as an Sql statement?"

So break it down and use the power of Google to help you:
1. find the index of the last of a non-numeric character: sql get last alpha character index - Google Search[^] gives us this: Sql find the last non-numeric character in a string [duplicate][^]
2. then you can increment the numeric value
3. lastly, concat/join the string back together: sql concat string - Google Search[^] - there are a number of examples.

Hope this helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900