Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have auto increase the numerical value but I want to know how to increase a mixed value like 'cg123'. Need to store database and retrieve it.

What I have tried:

I have tried numerical increment method. Code below attached
Posted
Updated 28-Nov-17 22:05pm

Hi

You can get expected by modify the Table Schema by adding new Column for EmpCode like below

create  table tblEmpCodeTest (ID bigint identity(1 ,1),
EmpCode as 'CG'+Replicate('0', 3 - LEN(ID))+ cast(ID as varchar)  persisted not null primary key ,
FirstName varchar(10))


Note : MS SQL Server DB Query

Thanks
Siva Rm K
 
Share this answer
 
Use IDENTITY (Property)[^] for auto increment.

Take a look at this article Auto generate auto incremented unique alphanumeric id or number in sql server[^] This article refer exactly same things you are looking for.
 
Share this answer
 
 
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