I am trying to increment an ID in my column.
The first value is "SERVI200000" and want to increment it so that it shows:
"SERVI200001","SERVI200002" when new data is entered to it.
Can somebody help with this?
I am trying to increment an ID in my column.
The first value is "SERVI200000" and want to increment it so that it shows:
"SERVI200001","SERVI200002" when new data is entered to it.
Can somebody help with this?
You can create table something similar as below which will take care of auto increment number as per your requirement.
On top of that, since it is computed column you don't have to supply value explicitly every time you insert value.
CREATE TABLE dbo.YourTable
(ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
PID AS 'SERVI' + RIGHT('200000' + CAST(ID AS VARCHAR(7)), 7) PERSISTED,
PersonName VARCHAR(50)
)
INSERT INTO dbo.YourTable(PersonName)
VALUES ('Name1')