Click here to Skip to main content
15,922,155 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i want to increment/ increase given serial number by one for next EG'4'(i must be able to chose number of rows i want) rows.

eg if number is

ECR12345432123456543216 then following number must be
ECR12345432123456543217
ECR12345432123456543218
ECR12345432123456543219

quantity of numbers and serial number are given.
there will be first three alphabet then 20 digits.

i want to increase serial number by one.

please need help.
Posted

Use below sql

SQL
declare @sNo varchar(23) = 'ECR12345432123456543217' ;
select left(@sNo,3) + convert(varchar, convert (decimal(20,0) ,right(@sNo,20)) +1 )
 
Share this answer
 
Hello,Try Following code

declare @str varchar(25)
set @str='ECR12345432123456543216'
Select Convert(decimal(25,0),Substring(@str,4,21))+1
 
Share this answer
 
Try split the string. One part is the 'ECR' chars, the other is the serial number 123456.....
Then increment the number part and construct a new string when done.

serialNumber += 1;

Or 

serialNumber = serialNumber + 1;

string newStr = ercString + serialNumber;


I'll let you figure how how to split the string.
 
Share this answer
 
Comments
ByakuyaKuchiki 1-Mar-13 5:23am    
i need SQL Query not C# statement
gvprabu 1-Mar-13 6:13am    
For SQL query we ll write... but we need to use NUMERIC(20,0) for that number. Because INT and BIG INT Data type and all we cant able to use. Where you are going to use this?
Hi

Try the following way....

SQL
DECLARE @SNo VARCHAR(30)='ECR12345432123456543216', @NextSNo VARCHAR(30)=''
 
SELECT @NextSNo='ECR'+RIGHT('00000000000000000000'+CAST(CAST(SUBSTRING(@SNo,4, 20) AS numeric(20,0))+1 AS VARCHAR(20)),20)
 
SELECT @SNo 'SNo', @NextSNo 'NextSNo'


Regards,
GVPrabu
 
Share this answer
 
v2

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