Last post Sep 23, 2016 11:54 AM by sudip_inn
Sep 22, 2016 09:40 AM|sudip_inn|LINK
generate auto alpha numeric id in sql server like ACX-01, ACX-02, ACX-10, ACX-100, ACX-1000
suppose first 4 char is fixed and numeric part will be like 01,02.....100,101....1000 upto 1000000
the serial no will be inserted into db fields. so we have to fetch numeric part first and then increment.
how to achieve with normal code in store proc and also how to do it with sequence.
Sep 23, 2016 04:59 AM|eralper|LINK
I used a computed column which adds the fixed string and the identity column of the table as I described at tutorial
Custom Sequence String as SQL Identity Column in SQL Server
The idea is implemented as follows
CREATE TABLE tbl...
id int IDENTITY(1,1),
SerialColumn as dbo.ComputedColFunction('fixedstring', CAST(id as nvarchar(10)),6,'0'),
I hope it is useful
Sep 23, 2016 09:25 AM|sudip_inn|LINK
not very clear. need sample code which i can run at my end.
Sep 23, 2016 11:54 AM|sudip_inn|LINK
i got my answer. without any store proc how easily we can do this
CREATE TABLE tbEmployee
EmpId INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
EmpCode AS 'EMP' + RIGHT('0000'+ CONVERT(VARCHAR(5),EmpId),5) PERSISTED,
--INSERT RECORDS IN TABLE
INSERT INTO tbEmployee (EmployeeName,Age,Gender)VALUES
--CHECK INSERTED RECORD
SELECT * FROM tbEmployee
code taken from