Quantcast
Channel: CSharp Forum Latest Questions
Viewing all articles
Browse latest Browse all 32111

Auto Increment nvarchar Column in Sql Server 2008

$
0
0


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

Viewing all articles
Browse latest Browse all 32111

Trending Articles