create table Customers
(
dbID int identity not null primary key,
CustomerName varchar(100)
)
Go
create function CustomerNumber (@id int)
returns char(5)
as
begin
return 'C' + right('0000' + convert(varchar(10), @id), 4)
end
Go
alter table Customers add CustomerNumber as dbo.CustomerNumber(dbID)
Go
INSERT INTO Customers(CustomerName) VALUES ('Name')
INSERT INTO Car(CustomerID) VALUES (SCOPE_IDENTITY())
Go
Loading
Jignesh TrivediPosted Feb 5, 2013, 5:13 AM
hi,
here your quetion is not cleared.
are you looking auto increment varchar datatype?
please refer below link it might help you to solved this issue.
http://beta.c-sharpcorner.com/Forums/Thread/163919/hi-how-to-auto-increment-for-text-and-char-in-sql-table.aspx
hope this will help you.