Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 AutoGenerate Customer ID

Author  Topic 

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-09-15 : 22:02:00
hi

How do i auto generate customer id? For example, C000001,C000002,C000099

I am using Nvarchar(50) for CustID field

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-16 : 03:17:09
Refer this

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-09-16 : 08:53:08
[code]create table computed (
incr int not null identity(1, 1),
computed as ('C' + right(cast((100000000 + incr) as varchar(9)), 8)) persisted not null primary key clustered,
fistname varchar(25)
)

insert into computed (fistname) select 'Lumbago'

select * from computed[/code]

- Lumbago
Go to Top of Page
   

- Advertisement -